|
1 | | -# How to set CheckBox value based on the value change of another CheckBox column in winforms datagrid? |
2 | | -This example illustrates how to set CheckBox value based on the value change of another CheckBox column in winforms datagrid |
| 1 | +# How to Set Checkbox Value Based on the Value Change on Another Checkbox Column in WinForms DataGrid? |
| 2 | + |
| 3 | +This example illustrates how to set CheckBox value based on the value change on another CheckBox column in [WinForms DataGrid](https://www.syncfusion.com/winforms-ui-controls/datagrid) (SfDataGrid). |
| 4 | + |
| 5 | +You can set the value for a check box in one check box column when enabling or disabling it in another check box column using the [SfDataGrid.CellCheckBoxClick](https://help.syncfusion.com/cr/windowsforms/Syncfusion.WinForms.DataGrid.SfDataGrid.html#Syncfusion_WinForms_DataGrid_SfDataGrid_CellCheckBoxClick) and [SfDataGrid.CurrentCellActivating](https://help.syncfusion.com/cr/windowsforms/Syncfusion.WinForms.DataGrid.SfDataGrid.html#Syncfusion_WinForms_DataGrid_SfDataGrid_CurrentCellActivating) events. |
| 6 | + |
| 7 | +#### C# |
| 8 | + |
| 9 | +``` csharp |
| 10 | +this.sfDataGrid1.CellCheckBoxClick += sfDataGrid1_CellCheckBoxClick; |
| 11 | +this.sfDataGrid1.CurrentCellActivating += sfDataGrid1_CurrentCellActivating; |
| 12 | + |
| 13 | +void sfDataGrid1_CurrentCellActivating(object sender, CurrentCellActivatingEventArgs e) |
| 14 | +{ |
| 15 | + if (e.DataColumn.GridColumn.MappingName == "ClosedStatus") |
| 16 | + e.Cancel = true; |
| 17 | +} |
| 18 | + |
| 19 | +void sfDataGrid1_CellCheckBoxClick(object sender, CellCheckBoxClickEventArgs e) |
| 20 | +{ |
| 21 | + if (e.Column.MappingName == "ClosedStatus") |
| 22 | + e.Cancel = true; |
| 23 | + |
| 24 | + if (e.Column.MappingName == "IsClosed") |
| 25 | + { |
| 26 | + (e.Record as OrderInfo).ClosedStatus = e.NewValue == CheckState.Checked; |
| 27 | + } |
| 28 | +} |
| 29 | +``` |
| 30 | + |
| 31 | +#### VB |
| 32 | + |
| 33 | +``` vb |
| 34 | +AddHandler Me.sfDataGrid1.CellCheckBoxClick, AddressOf sfDataGrid1_CellCheckBoxClick |
| 35 | +AddHandler Me.sfDataGrid1.CurrentCellActivating, AddressOf sfDataGrid1_CurrentCellActivating |
| 36 | + |
| 37 | +Private Sub sfDataGrid1_CurrentCellActivating(ByVal sender As Object, ByVal e As CurrentCellActivatingEventArgs) |
| 38 | + If e.DataColumn.GridColumn.MappingName = "ClosedStatus" Then |
| 39 | + e.Cancel = True |
| 40 | + End If |
| 41 | +End Sub |
| 42 | + |
| 43 | +Private Sub sfDataGrid1_CellCheckBoxClick(ByVal sender As Object, ByVal e As CellCheckBoxClickEventArgs) |
| 44 | + If e.Column.MappingName = "ClosedStatus" Then |
| 45 | + e.Cancel = True |
| 46 | + End If |
| 47 | + |
| 48 | + If e.Column.MappingName = "IsClosed" Then |
| 49 | + TryCast(e.Record, OrderInfo).ClosedStatus = e.NewValue = CheckState.Checked |
| 50 | + End If |
| 51 | +End Sub |
| 52 | +``` |
| 53 | + |
| 54 | + |
0 commit comments