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.