I have a DataGridView in a Winforms application. I want to select a set of rows in it and sort those rows by a column (Timestamp)…
The rest of the rows should remain as they originally were..
Can this be done using the sort property of DGV
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No
The
Sortmethod on theDataGridViewis used for a bit more simple sorting. Such as Ascending or Descending sorting and theSortOrderproperty is also just for “simple” sorting.Can this behavior be implemented? Sure.
I think the easiest way to do this, is this:
DataGridViewHowever you need to think about how you want to handle if you selecte items that are not followed by each other, for instance if you select index
{ 1, 3, 6, 9 }you might stil lwant to append this to index1.Edit
Okay so I played around with this a little bit and came up with a way that you can implement this. It’s not very optimized but you’ll get the idea on how I meant.
First of all this is my
SortSelectedIndices-method that I use:Then I call it like this:
And this prints out the following:
I am just using a simple method here to print this out to the console:
So what you can do is to have a “sort”-button, when it’s pressed you invoke
SortSelectedIndicesand then rebind the list when you’re done. Remember I have not profiled or refactored this code, it might not be as fast as you like, I just want to give you an idea on what you can do to acheive the solution.