Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble with Datagridview.ClearSelection()

Tags:

c#

.net

winforms

I want my (readonly,fullrowselect) datagridviews to have no selected rows when the form is loaded. I tried .ClearSelection in the forms constructor after setting their datasource but it doesn't work (i would really like to know why...).

Then i tried in the Form_load event but it won't clear the selection on the datagridviews i have placed on the not immediately visible tab containers.

Am i doing something wrong? I could do it in the Layout event of each tab page but then it will deselect the rows every time the user changes tab, which is not a desired behavior.

like image 734
francis Avatar asked Oct 25 '10 15:10

francis


2 Answers

I found out that it's not working in FormLoad but works fine in FormShown. So you only have to set your dataGridView1.ClearSelection in your FormShown and everything works fine.

like image 75
Manfred Avatar answered Sep 17 '22 02:09

Manfred


Try call an

yourGridView.Update(); 

after calling the

ClearSelection();

to redraw the grid.

like image 31
pjnovas Avatar answered Sep 17 '22 02:09

pjnovas