Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 643
  • Last Modified:

How sort datatable by multiple columns (actual underlying data)

How can I sort a datatable using multiple columns?  I want to sort the actual UNDERLYING data.
0
RobertNZana
Asked:
RobertNZana
  • 3
  • 3
1 Solution
 
sunithnairCommented:
like this
    Dim view As DataView = DataTable1.DefaultView
    view.Sort = "State, ZipCode DESC"
 
Then use the view to bind to the grid

Open in new window

0
 
RobertNZanaAuthor Commented:
But does that sort the underlying data?  In my function (that sorts the dataview) I return the datatable...

Dim dv As New DataView(dtTracking, "", "Company, ContactName, TrackingType", DataViewRowState.OriginalRows)
Return dv.Table

But when I bind the datagrid it's not sorted properly.
0
 
RobertNZanaAuthor Commented:
See code below.  I setup my sort for the dv, but when I start looping thru it (for each) it's not adhering to the sort!

Dim dv As New System.Data.DataView(dtGridview, "", "Company, ContactName, TrackingType", Data.DataViewRowState.OriginalRows)
 
For Each dr As System.Data.DataRow In dv.Table.Rows

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
sunithnairCommented:
Why dont you bind the DataView itself as I mentioned in my 1st post?
0
 
sunithnairCommented:
Or try like this http://msdn.microsoft.com/en-us/library/a8ycds2f.aspx
Dim v As DataView = dtTracking.DefaultView;
v.Sort="Company, ContactName, TrackingType";
Return v.ToTable(); 

Open in new window

0
 
RobertNZanaAuthor Commented:
Thanks!!!!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now