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