auxcom Posted April 18, 2004 Posted April 18, 2004 I'm having a problem on sorting a dataset after I insert a new row and call the AcceptChanges of the dataset. I sort a dataset like this: ds.Tables(0).DefaultView.Sort = SortField But this will not work. The new record is still located at the end of the dataset. I see this when I populate a listview with the dataset. I hope someone can help me. Thanks! Quote
Moderators Robby Posted April 18, 2004 Moderators Posted April 18, 2004 Do you bind the grid after you sort? Quote Visit...Bassic Software
auxcom Posted April 18, 2004 Author Posted April 18, 2004 Well, I dont use a datagrid. I just a listview and I think there is databinding w/ a listview. Quote
georgepatotk Posted April 19, 2004 Posted April 19, 2004 U could do it when u are performing query? eg: "SELECT fields FROM table ORDER BY chosenfield" Quote George C.K. Low
Arch4ngel Posted April 19, 2004 Posted April 19, 2004 Maybe you could get the DefaultView and set the SortExpression. It work for me all the time. Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
Moderators Robby Posted April 19, 2004 Moderators Posted April 19, 2004 George, that's not an option, he is already using the Sort method of the defaultview. Arch4ngel, he's already doing that. Auxcom, it doesn't matter if it's a grid or listview, did you bind after you sorted? Quote Visit...Bassic Software
Arch4ngel Posted April 19, 2004 Posted April 19, 2004 Bang! 3 in 1 for Robby. Last solution... Did you bind ? :p Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
auxcom Posted April 20, 2004 Author Posted April 20, 2004 I like to edit my reply at post #3: I dont use a datagrid. I use a listview and I think there is no databinding w/ a listview. Here is my code for filling my listview. Private Function FillView() As Integer Dim dr As DataRow Dim lvi As ListViewItem ds.Tables(0).DefaultView.Sort = "Username ASC" lvw.Items.Clear() For Each dr In ds.Tables(0).Rows lvwUser.Items.Add(dr("Username")) Next End Function Quote
*Experts* Nerseus Posted April 20, 2004 *Experts* Posted April 20, 2004 Try something like this instead: Dim dr As DataRowView lvw.Items.Clear() For Each dr In ds.Tables(0).DefaultView lvwUser.Items.Add(dr("Username")) Next 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
auxcom Posted April 20, 2004 Author Posted April 20, 2004 Thanks Nerseus! It already work the way I want :-) I just add this line of code before the looping ds.Tables(0).DefaultView.Sort = "Username ASC" Quote
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.