CookieMonster24 Posted April 6, 2004 Posted April 6, 2004 I'm having problems sorting my dataview. If anyone could help that would be great. here is what i have (dt is my datatable) Dim dv As New DataView(dt, "", "", DataViewRowState.CurrentRows) dv.Sort = "ClientID" PrintTable(dv.table, "DataTable") ' using this to test the sort 'then i would like to replace my current datatable with what i just sorted i've also tried just sorting like this dt.defaultview.sort = "ClientID" but that still doesn't work. Private Sub PrintTable(ByVal t As DataTable, ByVal label As String) ' This function prints values in the table or DataView. Console.WriteLine("\n" + label) Dim row As DataRow Dim c As DataColumn For Each row In t.Rows For Each c In t.Columns Console.Write("\t{0}", row©) Next c System.Console.WriteLine("") Next row Console.WriteLine() End Sub Any ideas where i am going wrong? Quote
Administrators PlausiblyDamp Posted April 6, 2004 Administrators Posted April 6, 2004 By refering to the table property you are looking at the original unsorted table. If you databind to the dataview that will display sorted data, IIRC programatically you should be looking at the DataView's Item property. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
BlueJay924 Posted April 6, 2004 Posted April 6, 2004 How would i go about doing this? By refering to the table property you are looking at the original unsorted table. If you databind to the dataview that will display sorted data' date=' IIRC programatically you should be looking at the DataView's Item property.[/quote'] Quote
*Experts* Nerseus Posted April 7, 2004 *Experts* Posted April 7, 2004 Offhand, you'll need a new function PrintDataView that accepts a DataView instead of a DataTable. Then loop through a DataRowView collection instead of the Rows. You might change your PrintTable to be more generic, but since it looks like test code I'd just use two functions. -nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.