Articles in this section
Category / Section

How to load unbound checkbox column in a WinForms GridGroupingControl?

2 mins read

Unbound columns

You can add the unbound CheckBox columns to the WinForms GridGroupingControl by using the TableDescriptor.UnboundFields.Add() method. This method allows you to add the unbound fields to the GridGroupingControl. Unbound values can be provided in QueryValue event and any changes in the values can be stored back to the data store by handling the SaveValue event. Additionally, you can handle QueryCellStyleInfo event to customize unbound cells individually.

You can save the values elsewhere as the grouping grid does not maintain any data structure to store cell values. Since the values are unbound, they cannot be stored into bound data source too. In this example, a HashTable is used to save the values of unbound column. The example displays an unbound CheckBox column along with other bound columns. Refer to the following steps to have an unbound checkbox column in the GridGroupingControl.

1. Adding an unbound column

C#

//adding unbound column and setting type.
this.gridGroupingControl1.TableDescriptor.UnboundFields.Add("print");
this.gridGroupingControl1.TableDescriptor.Columns["print"].Appearance.AnyRecordFieldCell.CellType ="CheckBox";

VB

'adding unbound column and setting type.
Me.gridGroupingControl1.TableDescriptor.UnboundFields.Add("print")
Me.gridGroupingControl1.TableDescriptor.Columns("print").Appearance.AnyRecordFieldCell.CellType ="CheckBox"

2. Creating Hashtable to store unbound column values.

C#

Hashtable checkboxvalues=new Hashtable();

VB

Dim checkboxvalues As New Hashtable()

3. Declaration of the events

Then QueryValue event is used to edit the values in the checkbox. The SaveValue event is used to save the changes that you made in the checkbox.

C#

//events for saving the checkbox values entered.
this.gridGroupingControl1.TableDescriptor.QueryValue += new FieldValueEventHandler(unboundField_QueryValue);
this.gridGroupingControl1.TableDescriptor.SaveValue += new FieldValueEventHandler(unboundField_SaveValue);
//Getting the checkBox values in a hashtable.
private void unboundField_QueryValue(object sender, FieldValueEventArgs e)
{
    int RecordIndex =this.gridGroupingControl1.Table.PrimaryKeySortedRecords.IndexOf(e.Record);
    if (e.Field.Name == "print" && RecordIndex>=0)
    {
        object value = checkboxvalues[RecordIndex];
        if (value != null)
           e.Value= value;
    }
}
//Setting the checkbox values from the hashtable.
private void unboundField_SaveValue(object sender, FieldValueEventArgs e)
{
    int RecordIndex =this.gridGroupingControl1.Table.PrimaryKeySortedRecords.IndexOf(e.Record);
    if (e.Field.Name == "print" && RecordIndex>=0)
    {
       checkboxvalues[RecordIndex] = e.Value;
    }
}

VB

'events for saving the checkbox values entered.
Private Me.gridGroupingControl1.TableDescriptor.QueryValue += New FieldValueEventHandler(AddressOf unboundField_QueryValue)
Private Me.gridGroupingControl1.TableDescriptor.SaveValue += New FieldValueEventHandler(AddressOf unboundField_SaveValue)
'Getting the checkBox values in a hashtable.
Private Sub unboundField_QueryValue(ByVal sender As Object, ByVal e As FieldValueEventArgs)
    Dim RecordIndex As Integer =Me.gridGroupingControl1.Table.PrimaryKeySortedRecords.IndexOf(e.Record)
    If e.Field.Name = "print" AndAlso RecordIndex>=0 Then
       Dim value As Object = checkboxvalues(RecordIndex)
       If value IsNot Nothing Then
           e.Value= value
       End If
    End If
End Sub
'Setting the checkbox values from the hashtable.
Private Sub unboundField_SaveValue(ByVal sender As Object, ByVal e As FieldValueEventArgs)
    Dim RecordIndex As Integer =Me.gridGroupingControl1.Table.PrimaryKeySortedRecords.IndexOf(e.Record)
    If e.Field.Name = "print" AndAlso RecordIndex>=0 Then
       checkboxvalues(RecordIndex) = e.Value
    End If
End Sub

The following screenshot illustrates the output.

Adding unbound checkbox column

Figure 1: Adding unbound CheckBox column in GridGroupingControl

Samples:

C#: UnboundCheckBoxColumn-C#

VB: UnboundCheckBoxColumn-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 load unbound checkbox column in a 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 forumsDirect-Trac, or feedback portal. We are always happy to assist you!

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please sign in to leave a comment
Access denied
Access denied