Hi Varsha,
Thank you for using Syncfusion products.
To achieve the desired functionality with checkbox set in columnheadercell, You need to handle TableControlCellClick, TableControl.MouseUp, TableControlCheckBoxClick, SaveCellText events.
You can customize the “ColumnHeaderCell” to have Checkbox that allows SelectAll/DeselectAll values in the CheckBox column using “QueryCellStyleInfo” event where ColumnHeaderCell CellType is set to CheckBox, “SaveCellText” event that saves the CheckBox Value and “TableControlCheckBoxClick” updates the corresponding values in the RecordFieldCell based on ColumnHeaderCell value.
<code>
void gridGroupingControl1_TableControlCheckBoxClick(object sender, GridTableControlCellClickEventArgs e)
{
GridTableCellStyleInfo style = (GridTableCellStyleInfo)e.TableControl.GetTableViewStyleInfo(e.Inner.RowIndex, e.Inner.ColIndex);
if (style.Enabled)
{
int column = this.gridGroupingControl1.TableModel.NameToColIndex("Column2");
Console.WriteLine("CheckBoxClicked");
if (style.Enabled && style.TableCellIdentity.TableCellType == GridTableCellType.ColumnHeaderCell)
{
chk = (bool)this.gridGroupingControl1.TableModel[style.TableCellIdentity.RowIndex, column].CellValue;
e.TableControl.BeginUpdate();
foreach (Record rec in e.TableControl.Table.Records)
{
int rowIndex = e.TableControl.Table.DisplayElements.IndexOf(rec);
GridTableCellStyleInfo rowStyle = (GridTableCellStyleInfo)e.TableControl.GetTableViewStyleInfo(rowIndex, column);
if (rowStyle.Enabled)
rec.SetValue("Column2", !chk);
}
e.TableControl.EndUpdate(true);
}
if (style.Enabled && (style.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell || style.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell) && style.TableCellIdentity.Column.Name == "Column2")
{
Record currentRecord = style.TableCellIdentity.DisplayElement.GetRecord();
bool curStatus = bool.Parse(style.Text);
e.TableControl.BeginUpdate();
foreach (Record r in e.TableControl.Table.Records)
{
if (r != currentRecord)
{
check = bool.Parse(r.GetValue(style.TableCellIdentity.Column.Name).ToString());
ht.Add(check);
}
}
e.TableControl.EndUpdate();
if (ht.Contains(curStatus) && !ht.Contains(!curStatus))
{
if (curStatus)
CheckBoxValue = false;
this.gridGroupingControl1.TableModel[2, column].CellValue = curStatus;
}
else if (!ht.Contains(curStatus))
{
this.gridGroupingControl1.TableModel[2, column].CellValue = curStatus;
CheckBoxValue = !curStatus;
}
ht.Clear();
}
}
this.gridGroupingControl1.TableControl.Refresh();
}
void gridGroupingControl1_SaveCellText(object sender, Syncfusion.Windows.Forms.Grid.GridCellTextEventArgs e)
{
GridTableCellStyleInfo style = (GridTableCellStyleInfo)e.Style;
if (style.Enabled && style.TableCellIdentity.TableCellType == GridTableCellType.ColumnHeaderCell)
{
this.CheckBoxValue = bool.Parse(e.Text);
e.Handled = true;
}
}
void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
if (e.TableCellIdentity.TableCellType == GridTableCellType.ColumnHeaderCell && e.TableCellIdentity.Column.Name == "Column2")
{
e.Style.CellType = "CheckBox";
e.Style.CellValueType = typeof(bool);
e.Style.CellValue = CheckBoxValue;
e.Style.ReadOnly = false;
e.Style.CellAppearance = GridCellAppearance.Raised;
e.Style.Enabled = true;
e.Style.Description = e.Style.CellValue.ToString();
}
e.Handled = true;
}
Please find the attached sample. If you have any more queries related to this, please provide your sample also.
Please let me know if you have any questions.
Regards,
Vinish Kumar K
GGCCheckBox348688726_dff2036.zip