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
AddHandler Me.gridGroupingControl1.TableDescriptor.QueryValue, 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 = CType(checkboxvalues(e.Record.Id), Boolean)
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());
}
}
AddHandler Me.gridGroupingControl1.TableDescriptor.SaveValue, 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 screenshot below 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 an unbound checkbox column at runtime in the WinForms GridGroupingControl.
You can refer
to our WinForms GridGroupingControl’s feature tour page to
know about its other groundbreaking feature representations. You can also
explore our WinForms GridGroupingControl documentation to
understand how to present and manipulate data.
For current
customers, you can check out our WinForms 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 WinForms
GridGroupingControl and other WinForms components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you