Multi-thread update of sorted Datagridview data, resulting in data dislocation

Source: Internet
Author: User

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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.