DataGridView Cancel the default selected row

Source: Internet
Author: User

Recently with WinForm DataGridView encountered a lot of problems, last night encountered a default selected row of the problem. DataGridView the first cell or row is selected by default after the data is added, I want to cancel its default selected row. The Datagridview1.clearselection () code is added to the binding data, and the first line is found to be selected after the form is started. Later on the Internet search, see a lot of people have encountered this problem, the solution is nothing more than that few lines of code. But I tried a few times do not work, baffled the solution.
Later only to know to put it in the form of the load event, so added the Form1_Load event a try, finally there is no default selected line. Not if the first row is selected by default after updating the DataGridView data, so I add clearselection () after DataGridView bind the data. This way, there is no default selection of rows, either after the form is started or when the data is re-updated.
The code is these, as long as the Lil bit place, any one of them can achieve the effect of unchecking.
Program code
Datagridview1.clearselection ();
Datagridview1.currentcell = null;
Datagridview1.rows[0]. Selected = false;

Records are ready to view

Of course, you should also pay attention to your DataGridView settings How to choose: Whether you can select multiple (multiselect), column Select the settings of the row selection.

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.