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
close icon

How to include checkbox for the expanded columns in gridgroupingcontrol

Hi,

I have a gridgroupingcontrol of 15 columns and I have dragged (selected) 5 columns. On expansions of these selected columns muliplt records are there. I need to add checkbox for all these records. On checking the checkbox and click on a button I need to export only the checked records to excel along with the header.

 


4 Replies

VK Vinish Kumar K Syncfusion Team August 24, 2012 03:31 AM UTC

Hi Varsha,

you can export the combo Box checked item to Excel using the following code.

ConverterOptions options = (ConverterOptions)this.comboBox1.SelectedItem;
converter.GroupingGridToExcel(this.gridGroupingControl1, saveFileDialog.FileName,options);


Please let me know if you have any further concerns.

Regards,

Vinish Kumar K

 


VA varsha August 28, 2012 09:58 AM UTC

Can you please provide me a sample code that would be really helpful.



VA varsha August 28, 2012 12:06 PM UTC

It is a checkbox and not a combobox, so the property SelectedItem cannot be applied here. I'm using webcontrols here. Can you please send me a sample code that would really help me a lot.



VK Vinish Kumar K Syncfusion Team August 30, 2012 04:46 AM UTC

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

Loader.
Live Chat Icon For mobile
Up arrow icon