We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to add unbound CheckBox column at run time in WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl
Tags: checkbox

Unbound column

To add an Unbound column in the grid, 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 for displaying and updating 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

 

Screenshot

Shows unbound checkbox column

 

Samples:

C# : CheckBox column at run time

VB : CheckBox column at run time

Reference link: https://help.syncfusion.com/windowsforms/classic/gridgroupingcontrol/managing-records-and-columns#unbound-columns

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment
Comments
Truong
Feb 17, 2020

Hi! Can i ask something about unbound field , please!

I have one CheckBox cell type with UnboundFields collection and i use GridExcelFilter too.

The problem is when i click at checkbox , the Record is not update value immediately, so that event SaveValue is not raised. This problem make the GridExcelFilter.RecordFiltersItemChanged can not raise too. But when i click at checkbox then click on another cell , the Record update immediately , and everything is ok. So there's a little annoyance with having to click on another cell so that the record can be updated before using GridExcelFilter.

Thank you for helping me. Best Regard

Reply

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile