Articles in this section

How to set a GridCheckBoxColumn value based on value of another Column in WinForms DataGrid(SfDataGrid)?

In WinForms DataGrid, you can set the value for a checkbox in one GridCheckBoxColumn when enable or disabling it in another GridCheckBoxColum using SfDataGrid.CellCheckBoxClick and SfDataGrid.CurrentCellActivating events.

FirstLevelNestedGrid.CellCheckBoxClick += FirstLevelNestedGrid_CellCheckBoxClick;
FirstLevelNestedGrid.CurrentCellActivating += FirstLevelNestedGrid_CurrentCellActivating;
private void FirstLevelNestedGrid_CurrentCellActivating(object sender, Syncfusion.WinForms.DataGrid.Events.CurrentCellActivatingEventArgs e)
{
    if (e.DataColumn.GridColumn.MappingName == "IsClosed1")
        e.Cancel = true;
}
 
private void FirstLevelNestedGrid_CellCheckBoxClick(object sender, Syncfusion.WinForms.DataGrid.Events.CellCheckBoxClickEventArgs e)
{
    var records = ((e.OriginalSender as DetailsViewDataGrid).DataSource) as List<OrderDetails>;
    var grid = e.OriginalSender as DetailsViewDataGrid;
    if (e.Record == null && e.Column.MappingName == "IsClosed")
    {
        if (e.NewValue.ToString() == "Checked")
        {
            (grid.Columns["IsClosed1"] as GridCheckBoxColumn).GetType().GetProperty("HeaderState", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(grid.Columns["IsClosed1"] as GridCheckBoxColumn, CheckState.Checked);
        }
        else
        {
            (grid.Columns["IsClosed1"] as GridCheckBoxColumn).GetType().GetProperty("HeaderState", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(grid.Columns["IsClosed1"] as GridCheckBoxColumn, CheckState.Unchecked);
        }
 
        for (int i = 0; i < records.Count; i++)
        {
            if (e.NewValue.ToString() == "Checked")
            {
                (records[i] as OrderDetails).IsClosed1 = true;
            }
            else
            {
                (records[i] as OrderDetails).IsClosed1 = false;
            }
        }
    }
    if (e.Column.MappingName == "IsClosed1")
        e.Cancel = true;
 
    if (e.Column.MappingName == "IsClosed" && e.Record != null)
    {
        (e.Record as OrderDetails).IsClosed1 = e.NewValue == CheckState.Checked;
    }
 
}

 

Demo to show the checkbox column state changes


View Sample in GitHub.

Conclusion

Hope you enjoyed learning about how to add additional attributes to appointments WPF Scheduler (Calendar).

You can refer to our WinForms DataGrid feature tour page to learn about its other groundbreaking feature representations. You can explore our WinForms DataGrid documentation to understand how to present and manipulate data.

For current customers, you can check out our Angular components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our Angular Diagram and other Angular components.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!



 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied