[英]VB.net sort column then sort off but retain rows position
I can sort datagridview column by automatic sortmode. 我可以通过自动sortmode对datagridview列进行排序。 But my problem is, when i set column is automatic sort that mean The "Status" column always in sort mode and if there have any data change it will move to anythere following sort mode 但是我的问题是,当我将列设置为自动排序时,这意味着“状态”列始终处于排序模式,并且如果有任何数据更改,它将移动到以下任何排序模式
I don't wanna this. 我不要 I just want sort on and then off but retain the row position. 我只想先排序然后关闭,但保留行位置。 I mean: 我的意思是:
step 1: when user change status of the "Status" column, it isn't sort data 步骤1:当用户更改“状态”列的状态时,它不是排序数据
step 2: then, when user click to column header, it sort data descending 步骤2:然后,当用户单击列标题时,它将对数据降序排序
step 3: after that, when user change any status of the "Status" column, it is not sort but retain rows position in datagridview (that mean row which status is changed, doesn't move to anywhere) 步骤3:此后,当用户更改“状态”列的任何状态时,它不是排序而是在datagridview中保留行位置(这意味着状态已更改的行不会移至任何位置)
is there any right way to achieve this? 有没有正确的方法来实现这一目标? Thanks you for you help. 谢谢您的帮助。
Here's what I suggest in this situation: 这是我在这种情况下的建议:
DataTable
, do so. 如果您的网格尚未绑定到DataTable
,请这样做。 DataTable
with data type Integer
. 向DataTable
添加一个额外的列,其数据类型为Integer
。 DefaultView
of the DataTable
and set the values in the extra column sequentially. 遍历DataTable
的DefaultView
并依次在Extra列中设置值。 Sort
property of the DefaultView
. 将该额外的列的名称分配给DefaultView
的Sort
属性。 That's it. 而已。 The data is now sorted by that numeric sequence in that column so you can make whatever changes you want to the rest of the data without affecting the order. 现在,数据将按照该列中的数字顺序进行排序,因此您可以对其余数据进行任何所需的更改,而不会影响顺序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.