This is a migrated thread and some comments may be shown as answers.

How to call the "click" method of the Header Checkbox?

0 Answers 97 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 16 Apr 2019, 09:17 PM

Hello Everyone,

I am working on a custom user control which has a GridView on it. I have a checkbox column and have the EnableHeaderCheckBox property set to TRUE.  The grid works great; I can click on the Header Checkbox and toggle all checkboxes, etc. However, I am trying to create a method to allow the consumers of this user control to programmatically Select All or Unselect All (basically, mimicking the functionality of the Header Checkbox).

I have tried these but they did not work:

1)

grid.SelectAll();
grid.ClearSelection();

2) 

foreach (var row in grid.Rows)
    row.IsSelected = true;

 

Only this one works, but it takes a little bit of time to select/unselect all rows: 

foreach (var row in grid.Rows)
    row.Cells["Select"].Value = true; //or false to unselect

 

When I click on the Header Checkbox, rows are selected/unselected immediately, which is what I am looking for. I also need to make sure that the grid_CellValueChanged event is fired.

 

Any help is greatly appreciated.

 

Thanks!

 

 

 

 

 

No answers yet. Maybe you can help?

Tags
GridView
Asked by
Alex
Top achievements
Rank 1
Share this question
or