Winform DataGridView Cancel the default selected row

Source: Internet
Author: User

Dilemma

There are many solutions on the Internet, but many readers do not take effect. The problem arises in the fact that many bloggers do not understand the relationship between the DataGridView binding and the current triggering event.

Repetition
private void Frm_Load(object sender, EventArgs e){    datagridview.AutoGenerateColumns = false;    DataTable dataTable = new DataTable();    for (int i = 1; i <= 7; i++)    {        dataTable.Columns.Add("DPN" + i.ToString());    }    DataRow row11 = dataTable.NewRow();    row11["DPN1"] = "Test1";    row11["DPN2"] = "Test1";    row11["DPN3"] = "Test1";    row11["DPN4"] = "Test1";    row11["DPN5"] = "Test1";    row11["DPN6"] = "Test1";    row11["DPN7"] = "Test1";    dataTable.Rows.Add(row11);    datagridview.DataSource = dataTable;    datagridview.ClearSelection = false;}

Use datagridview.ClearSelection = false; is a lot of blog's solution, but in this example does not take effect!!!

Solve

In fact, it's easy to use DataBindingComplete events. This event occurs after the data source binding is complete.

private void datagridview_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e){    datagridview.ClearSelection();}
Thank

Colleague Phantomsix

Statement

This article uses the Creative Commons Attribution-Non-commercial use-share 2.5 Chinese mainland License Agreement license in the same way, publishes in CSDN and the blog Garden, welcome the reader to reprint, but does not have the author consent must retain this paragraph statement, and in the article page obvious location gives the original text connection!

Winform DataGridView Cancel the default selected row

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.