Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 9th, 2013, 05:16 PM
jscottcarson jscottcarson is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 1 jscottcarson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 51 sec
Reputation Power: 0
Cool Sorting column in datagridview populated by array

Below is my code. I need to sort the output of the "z" column descending by value. Any ideas?

Private Sub btnTableDeg_Click(sender As Object, e As EventArgs) Handles btnTableDeg.Click

' Clears rows on button press and builds columns
DataGridView1.Rows.Clear()
DataGridView1.ColumnCount = 3

DataGridView1.Columns(0).HeaderText = "Field of Study"
DataGridView1.Columns(1).HeaderText = "1981"
DataGridView1.Columns(2).HeaderText = "2006"

' One dimensional arrays initializing values
Dim x() As String = {("Business"), ("Computer & info.science"), ("Education"), ("Engineering"), ("Social science and history")}
Dim y() As Integer = {("200,521"), ("15,121"), ("108,074"), ("63,642"), ("100,513")}
Dim z() As Integer = {("318,042"), ("47,480"), ("107,238"), ("67,045"), ("161,485")}

'Calling output from arrays for datagridview
DataGridView1.Rows.Add(x(0), (y(0)), z(0))
DataGridView1.Rows.Add(x(1), (y(1)), z(1))
DataGridView1.Rows.Add(x(2), (y(2)), z(2))
DataGridView1.Rows.Add(x(3), (y(3)), z(3))
DataGridView1.Rows.Add(x(4), (y(4)), z(4))

End Sub

Reply With Quote
  #2  
Old February 10th, 2013, 03:16 PM
couttsj couttsj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Posts: 165 couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 16 h 44 m 37 sec
Reputation Power: 43
I presume that the data you have provided is sample data only, and that the real data will come from another and larger source. The simplest and most flexible way is to load the data into a database, and then bind your DataGrid to the database. That way you can sort the data any way you want to simply by changing the record source and refreshing the grid. For example, you can have the program respond to a click on any of the column headers to sort the records according to that particular column.

J.A. Coutts

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Sorting column in datagridview populated by array

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap