Sorting selected rows in DataGridView

后端 未结 5 757
走了就别回头了
走了就别回头了 2020-12-19 12:13

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 rema

5条回答
  •  盖世英雄少女心
    2020-12-19 12:58

    Definitely, the DataGridView cannot do this. So, the best solution would be to create a new collection (List), populate it with selected rows from the GridView and finally use its Sort method to order these rows. To sort data by a certain column, you can either write a custom IComparer class and pass it to the Sort method or use Linq:

    var orderedList = someList.OrderBy(obj => obj.TimeStampField);

提交回复
热议问题