Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datagridview Cell Selected After ClearSelection

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 ?

like image 777
Akshay J Avatar asked Oct 11 '22 14:10

Akshay J


1 Answers

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.

like image 62
joaopintocruz Avatar answered Oct 14 '22 05:10

joaopintocruz