How do I have an unbound checkbox column in a GridGroupingControl?
(Views :2234)

There are three steps to have an unbound checkbox column in the GridGroupingControl.

1. Add the unbound column to the GridGroupingControl.

C#
this.gridGroupingControl1.TableDescriptor.UnboundFields.Add("ColumnName");
VB
Me.gridGroupingControl1.TableDescriptor.UnboundFields.Add("ColumnName")

2. A bounded column has it own datastore to store the values entered in it. But in an unbound column there is no datastore present in it, so it has to be handled manually adding any datastore (arraylist,hashtable,arrays,etc..) present.

C#
Hashtable checkboxvalues=new Hashtable();
VB
Private checkboxvalues As New Hashtable()

3. Then QueryValue event is used to edit the values in the checkbox. The SaveValue event is used to save the changes made by the user in the checkbox.

Declaration of the events:

C#
this.gridGroupingControl1.TableDescriptor.QueryValue += new FieldValueEventHandler(unboundField_QueryValue);
this.gridGroupingControl1.TableDescriptor.SaveValue += new FieldValueEventHandler(unboundField_SaveValue);
private void unboundField_QueryValue(object sender, FieldValueEventArgs e)
{
int RecordIndex =this.gridGroupingControl1.Table.PrimaryKeySortedRecords.IndexOf(e.Record);
if (e.Field.Name == "ColumnName" && RecordIndex>=0)
{
object value = checkboxvalues[RecordIndex];
if (value != null)
e.Value= value;
}
}
private void unboundField_SaveValue(object sender, FieldValueEventArgs e)
{
int RecordIndex =this.gridGroupingControl1.Table.PrimaryKeySortedRecords.IndexOf(e.Record);
if (e.Field.Name == "ColumnName" && RecordIndex>=0)
{
checkboxvalues[RecordIndex] = e.Value;
}
}
VB
AddHandler Me.gridGroupingControl1.TableDescriptor.QueryValue, AddressOf unboundField_QueryValue
AddHandler Me.gridGroupingControl1.TableDescriptor.SaveValue, AddressOf unboundField_SaveValue
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 = "ColumnName" AndAlso RecordIndex >= 0 Then
Dim value As Object = checkboxvalues(RecordIndex)
If Not (value Is Nothing) Then
e.Value = value
End If
End If
End Sub
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 = "ColumnName" AndAlso RecordIndex >= 0 Then
checkboxvalues(RecordIndex) = e.Value
End If
End Sub

Sample:

http://websamples.syncfusion.com/samples/kb/grid.windows/GGCUnboundColumn/main.htm

::adCenter::