How to add unbound field in WinForms GridGroupingControl with datasource as BindingList?
Unbound column
You can add
the unbound column using UnboundFields property from WinForms
GridGroupingControl class and if you want to save the values in
unbound column you can use the SaveValue and QueryValue event.
You can get the saved values from SaveValue event. This value will be
maintained in a Hashtable and then this value assigned to
the unboundfield by using QueryValue event.
C#
// Maintain the typed values in unbound column
Hashtable UnboundValues = new Hashtable();
this.gridGroupingControl1.TableDescriptor.UnboundFields.Add("UnboundField");
this.gridGroupingControl1.TableDescriptor.QueryValue += new FieldValueEventHandler(TableDescriptor_QueryValue);
this.gridGroupingControl1.TableDescriptor.SaveValue += new FieldValueEventHandler(TableDescriptor_SaveValue);
void TableDescriptor_SaveValue(object sender, FieldValueEventArgs e)
{
if (e.Field.Name == "UnboundField")
{
UnboundValues[e.Record.Id] = e.Value;
}
}
void TableDescriptor_QueryValue(object sender, FieldValueEventArgs e)
{
if (e.Field.Name == "UnboundField")
{
e.Value = UnboundValues[e.Record.Id];
}
}
' Maintain the typed values in unbound column
Private UnboundValues As New Hashtable()
Me.gridGroupingControl1.TableDescriptor.UnboundFields.Add("UnboundField")
AddHandler gridGroupingControl1.TableDescriptor.QueryValue, AddressOf TableDescriptor_QueryValue
AddHandler gridGroupingControl1.TableDescriptor.SaveValue, AddressOf TableDescriptor_SaveValue
Private Sub TableDescriptor_SaveValue(ByVal sender As Object, ByVal e As FieldValueEventArgs)
If e.Field.Name = "UnboundField" Then
UnboundValues(e.Record.Id) = e.Value
End If
End Sub
Private Sub TableDescriptor_QueryValue(ByVal sender As Object, ByVal e As FieldValueEventArgs)
If e.Field.Name = "UnboundField" Then
e.Value = UnboundValues(e.Record.Id)
End If
End Sub
Samples:
C#: UnboundFields_CS
VB: UnboundFields_VB
Reference Link: Unbound Columns
Conclusion
I hope you
enjoyed learning about how to add unbound field in GridGroupingControl
with datasource as BindingList.
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!