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;