Click here to Skip to main content
15,034,432 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have bound data from SQL Database . i want to add feature that user can reorder rows while viewing the data. but, i can go with code that will work for Unbound data. Because reordering is my first concern.

What I have tried:

i tried nothing . i dont know how to do
Posted
Updated 18-Jul-21 4:37am

Do you mean:
Sorting data in DataGridView control - Windows Forms .NET Framework | Microsoft Docs[^]
Or:
DataGridView.Sort Method (System.Windows.Forms) | Microsoft Docs[^]
If not, you are going to have to be a lot more specific about what you are trying to achieve and why it's a problem for you.
   
Comments
LuQman Asif 18-Jul-21 18:12pm
   
I want to add drag and drop feature. Where user can drag any row and drop where he wants. So in this way he can reorder the data.
OriginalGriff 19-Jul-21 0:58am
   
If it wasn't databound then it's fairly easy by the look of things:
https://social.msdn.microsoft.com/Forums/en-US/16b0a44e-35a0-4bc8-9ccd-ec2c62c95a55/select-and-drag-a-datagridview-row-with-a-single-click?forum=winforms
shows the code.

But data bound is more complicated: you will hee to use much the same code, to identify where the data to move comes from and where it is to go, and then manually rearrange the rows in the bound data source.
That's a relatively complicated job, particularly when you have multiple row selections!

What I did using a music track List (without the drag and drop, but with "up", "down", "To Top", and "To Bottom" buttons) was to remove all the selected tracks to a new list, then locate the position to put them and Insert them all there.
The same approach should work for all data collections.
LuQman Asif 20-Jul-21 12:40pm
   
ok sir i can change my data from bound to unbound. Now plz give me code of reordering


If you have a DataTable, and you want to display the content in a DataGridView, it tends to be best to set any sorting and filtering via the DataTable's DefaultView, and then display the content of that DefaultView in the DataGridView.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900