Multi-thread update of sorted Datagridview data triggers the auto-sort time of the Datagridview dview and sorts the data again, resulting in an error in subsequent update of the data.
Solution:
Method 1: Set the table header attribute of the Datagridview, and set the DataGridViewColumnSortMode.
1. If the default sorting header DataGridView. SortedColumn exists,
Then:
DataGridViewColumn column = dgv. SortedColumn; // default sorting column. SortMode = DataGridViewColumnSortMode. NotSortable; // you can specify not to sort the column.
2. If no default sorting table header exists, you need to traverse the Datagridview dview to set the table header attribute.
For (int I = 0; I <dgv. colums. cout; I ++) {// The specific attribute is forgotten, that is, each header object (column) column is obtained. sortMode = maid. notSortable ;}
3. After running, sort again:Set the property to the original property.
Method 2: perform a one-to-one correspondence between a column and search for each column. Disadvantage: the matching speed is slow when the data volume is large. The advantage is that you can watch videos in auto-sort order in real time.