I have been frustrated by this weird behavior of DataGridView.
When its databind-ed, one cell gets selected even when the grid does not have focus. I have adopted certain workarounds like this
this.ActiveControl = textBoxPartySearch;
dataGridView1.Refresh();
dataGridView1.ClearSelection();
dataGridView1.CurrentCell = null;
e.Handled = true;
as suggested in this question of mine : Remove blue colored row from DataGridView WinForms
But this workaround does not work sometimes and making the code messy.
Is there any other free datagridview available that does not have this problem ?
I had this problem and managed to solve it by adding myDataGridView.ClearSelection();
at the end of every coded Event.
At the beginning just by having it at the end of my DataBind()
method was enough. Then I added some custom behaviors for row painting and other stuff and it stopped working (i.e., always had first row selected).
So I'd say if you added any custom Event, that may be the reason.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With