Programmatically change state of header checkbox (Winforms SfDataGrid)

Hello,

I need to be able to change the state (checked or unchecked) of the checkbox in the header of a checkbox column in SfDataGrid programmatically based on conditions outside of the SfDataGrid control.
I've come across several other forum posts:

https://www.syncfusion.com/forums/55627/how-to-programatically-check-uncheck-checkbox-in-header-column
https://www.syncfusion.com/forums/125104/how-to-do-checkbox-in-sfdatagrid-header-or-group-header
https://www.syncfusion.com/forums/141254/how-to-set-the-checkbox-in-the-sfdatagrid-header-to-on-after-initial-loading

...but none of these do what I desire. Is there a way to do this functionality?

Thanks.

3 Replies 1 reply marked as answer

MA Mohanram Anbukkarasu Syncfusion Team November 18, 2020 11:58 AM UTC

Hi Brent, 

Thanks for contacting Syncfusion support.  

We have prepared a simple sample to achieve your requirement to check/uncheck the checkbox in the header cell of the GridCheckBoxColumn in a button click event. 


Please have a look at this sample and let us know if you require further assistance from us.  

Regards, 
Mohanram A. 


Marked as answer

ST Stoked November 18, 2020 04:01 PM UTC

This is perfect. All I needed was this line here:

(this.sfDataGrid1.Columns["IsClosed"] as GridCheckBoxColumn).GetType().GetProperty("HeaderState", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(this.sfDataGrid1.Columns["IsClosed"] as GridCheckBoxColumn, CheckState.Unchecked);

I will test in the near future, and if I have any issues I will respond to this thread.

Thank you.


MA Mohanram Anbukkarasu Syncfusion Team November 19, 2020 05:07 AM UTC

Hi Brent, 

Thanks for the update.  

We will wait to hear from you.  

Regards, 
Mohanram A. 


Loader.
Up arrow icon