Vb.net – How to prevent datagridview from selecting the first cell as currentcell on opening

datagridviewvb.net

I'm trying to find a way to prevent my datagridview from selecting the first cell as default cell. Right now I have code that turns the backcolor of the cells in my datagridview to red if negative numbers are in the cells on import. However this won't work properly in my first cell since its already highlighted by default on import. If anyone can find out how to turn the selecting of the cell off I would greatly appreciate it! 🙂

I know it must be something simple like DataGridView1.CurrentCell.Selected = False

Best Answer

Handle the DataBindingComplete event of the DataGridView as so:

private void myGrid_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
    myGrid.ClearSelection();
}
Related Topic