How to add unbound CheckBox column at runtime in WinForms GridGroupingControl?
Unbound column
To add
an Unbound column in the WinForms
GridGroupingControl, TableDescriptor. UnboundFields collection
can be used and the CheckBox cell type can be assigned in the
following way,
C#
this.gridGroupingControl1.TableDescriptor.UnboundFields.Add("print"); this.gridGroupingControl1.TableDescriptor.Columns["print"].Appearance.AnyRecordFieldCel.CellType = "CheckBox";
VB
Me.gridGroupingControl1.TableDescriptor.UnboundFields.Add("print")
Me.gridGroupingControl1.TableDescriptor.Columns("print").Appearance.AnyRecordFieldCel.CellType = "CheckBox"
The values of that Unbound field can be maintained through QueryValue and SaveValue events. An internal collection will be handled to display and update the values.
C#
this.gridGroupingControl1.TableDescriptor.QueryValue += new FieldValueEventHandler(unboundField_QueryValue);
private void unboundField_QueryValue(object sender, FieldValueEventArgs e)
{
if (e.Field.Name == "print" && checkboxvalues.Contains(e.Record.Id))
{
e.Value = (bool)checkboxvalues[e.Record.Id];
}
}
VB
Private Me.gridGroupingControl1.TableDescriptor.QueryValue += New FieldValueEventHandler(AddressOf unboundField_QueryValue)
Private Sub unboundField_QueryValue(ByVal sender As Object, ByVal e As FieldValueEventArgs)
If e.Field.Name = "print" AndAlso checkboxvalues.Contains(e.Record.Id) Then
e.Value = CBool(checkboxvalues(e.Record.Id))
End If
End Sub
C#
this.gridGroupingControl1.TableDescriptor.SaveValue += new FieldValueEventHandler(unboundField_SaveValue);
private void unboundField_SaveValue(object sender, FieldValueEventArgs e)
{
if (e.Field.Name == "print" && checkboxvalues.Contains(e.Record.Id))
{
checkboxvalues[e.Record.Id] = bool.Parse(e.Value.ToString());
}
}
VB
Private Me.gridGroupingControl1.TableDescriptor.SaveValue += New FieldValueEventHandler(AddressOf unboundField_SaveValue)
Private Sub unboundField_SaveValue(ByVal sender As Object, ByVal e As FieldValueEventArgs)
If e.Field.Name = "print" AndAlso checkboxvalues.Contains(e.Record.Id) Then
checkboxvalues(e.Record.Id) = Boolean.Parse(e.Value.ToString())
End If
End Sub
The below Screenshot illustrates the addition of an unbound checkbox column at runtime.
Samples:
C# : CheckBox column at runtime
VB : CheckBox column at runtime
Reference Link: Unbound Columns
Conclusion
I hope you
enjoyed learning about how to add unbound checkbox column at runtime in GridGroupingControl.
You can refer to our WinForms GridGroupingControl feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms GridGroupingControl documentation to understand how to create and manipulate data.
For current customers, you can check out our 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 other controls.
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 forums, Direct-Trac, or feedback portal. We are always happy to assist you!