Preventing ValueChanged to fire for all rows when column header Checkbox is clicked

1 Answer 100 Views
Buttons, RadioButton, CheckBox, etc GridView
Patgat
Top achievements
Rank 2
Iron
Iron
Iron
Patgat asked on 27 Mar 2023, 05:35 PM

Hi,

sorry for a very naïve question :

When using a GridViewCheckBoxColumn with subscription to both ValueChanged events and HeaderCellToggleStateChanged, if I uncheck the header checkbox, the ValueChanged event is fired for each existing (checkbox) row in the gridview.

This is not occuring when the header checkbox is checked (in which case only the HeaderCellToggleStateChanged event occurs).

How can I prevent this behavior (while still allowing two successive events if for example I uncheck the header and just after check a row checkbox).

I probably missed some doc somewhere about this ...

Thanks

Patrick

1 Answer, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 27 Mar 2023, 09:29 PM

Hello Patrick,

The ValueChanged event will be called when a cell changed its value. When the header checkbox check state is changed, this will change the cell values in this column and it is expected this event to be called for each cell. You can consider using the CellValueChanged event. The second event will be called when a cell changed its value and the focus moves away. In the event handler, you can check the ActiveEditor property from the event arguments. This property will be null when the user clicks on the cell header checkbox. You can check this and execute your custom logic there.

this.radGridView1.CellValueChanged += RadGridView1_CellValueChanged; ;
            this.radGridView1.HeaderCellToggleStateChanged += RadGridView1_HeaderCellToggleStateChanged;

private void RadGridView1_CellValueChanged(object sender, GridViewCellEventArgs e)
{
    if(e.ActiveEditor == null)
    {
// Custom logic
    }
}

private void RadGridView1_HeaderCellToggleStateChanged(object sender, GridViewHeaderCellEventArgs e)
{
          
}

Can you try this approach and let me know if it works for you? If not you share some more details regarding your requirement and I will think of a more suitable solution.

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Buttons, RadioButton, CheckBox, etc GridView
Asked by
Patgat
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or