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

EnableHeaderCheckBox to check only enabled check boxes

1 Answer 239 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jean-Bernard
Top achievements
Rank 1
Jean-Bernard asked on 10 Aug 2020, 01:26 PM

My grid has a checkbox column "MyColumn" that has EnableHeaderCheckBox enabled.  That column is disabled in the following manner using the CellFormatting event, code follows(did it this way due to need to show a tool tip).  When I click on the header check box, every check box, including the disabled ones, are checked.  I don't want those that are disabled to be checked.  I've tried using the event HeaderCellToggleStateChanged to modify the toggle value of the checkbox, it's not taking effect.  How can I do this?

 

 private void MyGrid_CellFormatting(object sender, CellFormattingEventArgs e)
        try
            {

                e.CellElement.RowElement.ToolTipText = @"";
                e.CellElement.Enabled = true;

            if (!(bool)e.Row.Cells["Condition1"].Value)
                {
                    e.CellElement.Enabled = false;
                    e.CellElement.RowElement.ToolTipText = @"Disabled condition 1 ";
                }
              

 

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 11 Aug 2020, 08:28 AM

Hello, Jean-Bernard,

If I understand your requirement correctly, you want to toggle only the check boxes belonging to cell elements that are not disabled. This custom behavior has to be achieved programmatically. 

Please have in mind that GridViewCheckBoxColumn offers the ShouldCheckDataRows property which determines whether the CheckBox in the header cell will be synced with the data cells. When true, the header check box will check the data cells and vice versa. It seems that for your scenario it would be more suitable to set this property to false and manage programmatically the checked value only for the data cells that you want. In other words, you will need to iterate the RadGridView.Rows collection and update the cells values to the desired rows.

It is important to note that if you have many rows in the grid, it would be good to wrap this code block of iterating the rows and managing the values in a RadGridView.BeginUpdate/ RadGridView.EndUpdate block. Thus, you will not refresh the grid which every value change.

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Tags
GridView
Asked by
Jean-Bernard
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or