Datagridview deselect the selected row by default

Source: Internet
Author: User
Recently, the winform datagridview encountered many problems. Last night, we encountered a default row selection problem. After adding data, the datagridview selects the first cell or the first row by default. I want to cancel the selected row by default. Therefore, the datagridview1.clearselection () clause is added to the bound data. CodeThe first line is selected after the form is started. After searching on the internet, I found that many people encountered this problem. The solution was just a few pieces of code. But I tried it several times, and I was puzzled ..
Later, I learned to put it into the load event of the form, so I added Form1_loadFinally, no rows are selected by default. If the data of the datagridview is updated, the first row is selected by default. Therefore, clearselection () is added after the data is bound to the datagridview (). In this way, no row is selected by default after the form is started or after data is updated.
The code is just a few. If you put them in the correct place, any one of them can achieve the effect of canceling the selection. Datagridview1.clearselection ();
// Maid = NULL;
// Datagridview1.rows [0]. Selected = false;

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.