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 Grid Control 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]; } }
VB
‘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
Screenshot
Samples:
C#: UnboundFields_CS
VB: UnboundFields_VB
Reference link: https://help.syncfusion.com/windowsforms/classic/gridgroupingcontrol/managing-records-and-columns#unbound-columns
Conclusion
I hope you enjoyed learning about how to add unbound field in WinForms GridGroupingControl with datasource as BindingList.
You can refer to our WinForms Grid Control’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms Grid Control documentation to understand how to present and manipulate data.
For current customers, you can check out our WinForms 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 Grid Control 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!