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

Checkbox in column header in GridGroupingControl

I have GridGroupingControl in that one column as checkbox. I want to add checkbox in the column's header. On clicking header checkbox, I want to check all checkboxes for this column and vise versa.

One solution in my mind is, change celltype of header cell to checkbox as in the attached file. But I faild to handle its events for checking and unchecking row checkboxed.

CheckBoxInHeader.zip

25 Replies

HA haneefm Syncfusion Team June 5, 2007 06:09 PM UTC

Hi Faisal,

Please refer this knowledgebase(KB) article that helps in having a checkbox in the header of a GridGroupingControl.
http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=346

Here is a sample on your requirement to have the check all effect when the header checkbox is clicked.
GGC_HeaderCB.zip

Best regards,
Haneef


RE rewf June 7, 2007 10:42 AM UTC

Hi Haneef,
Thanks for your reply. I have gained this functionality partially. Please note
segPermissions is my GridGroupingControl. I have attached the code
Now my problem is that if click a header checkbox, then this code check all its child checkboxes along with all other header checkboxes.

I want; if I clicked a header checkbox then only it children get checked.
Please note I am using column grouping in my case.

Regards,
Faisal Iqbal




GridGroupingControlHeadCheckBox.zip


JS Jeba S Syncfusion Team June 8, 2007 11:19 AM UTC

Hi Faisal,

Thank you for your attachment.

You can catch the CheckBoxClick of the Child table and do your checking inside this event handler.

this.gridGroupingControl1.GetTableControl("ChildTable").CheckBoxClick += new GridCellClickEventHandler

(Form1_CheckBoxClick);


Kindly let us know if this helps.

Best Regards,
Jeba.


RE rewf June 8, 2007 01:19 PM UTC

Sorry, Can you help me with some code


RA Rajagopal Syncfusion Team June 9, 2007 12:26 AM UTC

Hi Faisal,

Please try the below sample that checks all the records on the maintable when the header is checked and not the child checkboxes.

http://www.syncfusion.com/Support/user/uploads/GGC_Checkbox_10609389.zip

Let us know if this helps.
Regards,
Rajagopal


RE rewf June 18, 2007 01:25 PM UTC

Hi,

I have attached a sample. Now probelm is On cliking header checkbox very first time, nothing happens. And on second click it will check/uncheck its child checboxes.
Pelase update this code and upload it with you message.

Thanks!
Faisal Iqbal

CheckboxinHeader0.zip


HA haneefm Syncfusion Team June 18, 2007 06:03 PM UTC

Hi Faisal,

Please refer to the modified sample and let me know if this helps.
ModifiedCheckboxinHeader.zip

Best regards,
Haneef


RE rewf June 21, 2007 08:36 AM UTC

Sorry, problem is still there. Because if I click a head checkbox, then this will check/uncheck all checkboes for other header.
Please, upload is again after fixing.

Regards,
Faisal Iqbal


HA haneefm Syncfusion Team June 21, 2007 10:49 PM UTC

Hi Fa,

You could have an Hashtable, which takes the key of the corresponding group column header as the hashkey and the associated tagvalue as the hashValue. You can retrieve the corresponding hashvalue anytime while clicking the column header checkbox cell. Below is a sample that implements this task. Please try this and let me know if this helps.

Sample :ModifiedCheckboxinHeader.zip

Best regards,
Haneef


RE rewf June 22, 2007 06:44 AM UTC

Sorry Hannef,

Noting is solved. When I checked a header, Its checked all it child checkboes and additionaly uncheck all other header checkboxes.
I have reported this issue in my previous mail, but your updated code have not solution for it.

Thanks
Faisal Iqbal


RE rewf July 2, 2007 03:37 PM UTC

Hanif,

No response from you. I am waiting for you. Kindly fix this issue.

Thanks.
Faisal Iqbal


HA haneefm Syncfusion Team July 2, 2007 08:34 PM UTC

Hi Faisal,

Below is a modified sample that shows you "How to add CheckBox in a Grouped Column Header?" .Please try the attached sample and let me know if you are looking something different.
ModifiedCheckboxinHeader22.zip

Best regards,
Haneef


RE rewf July 2, 2007 11:47 PM UTC

Yes Hanif,

Yes this what I needed. Thanks a lot.

Regards,
Faisal Iqbal


FB Felipe Bahiana Almeida October 28, 2015 06:35 PM UTC

I have a similar problem but I could not see the article in the knowledge base, nor download the samples.
Can you please update the links ?

My problem is as follows:
1 - I create a grid with a dynamic number of columns. The values on each column will be the data used on a chart. 
2 - When the user clicks in one checkbox I will hide or show the series on the chart and do some calculations with it.
3 - I need a way to have one master checkbox that checks/unchecks them all.

Thanks in advance


SA Solai A L Syncfusion Team October 29, 2015 09:07 AM UTC

Hi Felipe,

Thank you for using Syncfusion products.

Please refer the below KB to add check box in gridgroupingcontrol column header and save its checked state value using SaveCellText event.

KB Link :
https://www.syncfusion.com/kb/688/how-do-i-place-a-checkbox-in-a-header-cell-of-the-gridgroupingcontrol

Thanks & Regards,
AL.Solai.


FB Felipe Bahiana Almeida October 29, 2015 12:36 PM UTC

Thanks Solai, the difference from what I need is that I must show the column header (text) along with the checkbox.
Could you help me ?


FB Felipe Bahiana Almeida October 29, 2015 01:55 PM UTC

I Changed this code to align the checkbox on the left but did not work

Private Sub gridGroupingControl1_QueryCellStyleInfo(ByVal sender As Object, ByVal e As GridTableCellStyleInfoEventArgs)
            If e.TableCellIdentity.TableCellType = GridTableCellType.ColumnHeaderCell AndAlso e.TableCellIdentity.Column.Name = "Column2" Then
                e.Style.TextAlign = GridTextAlign.Left
                e.Style.Text = "Column 2"
                e.Style.CellType = "CheckBox"
                e.Style.CellValueType = GetType(Boolean)
                e.Style.CellValue = CheckBoxValue
                e.Style.ReadOnly = False
                e.Style.CellAppearance = GridCellAppearance.Raised
                e.Style.Enabled = True
            End If
e.Handled = True
End Sub


SA Solai A L Syncfusion Team October 30, 2015 08:44 AM UTC

Hi Felipe,

Thank you for your update.

If you want to set text for checkbox , you need to use Description  property. Please refer the below code example for reference.

Code Example :

 Private Sub gridGroupingControl1_QueryCellStyleInfo(ByVal sender As ObjectByVal As GridTableCellStyleInfoEventArgs)
        
If ((e.TableCellIdentity.TableCellType GridTableCellType.ColumnHeaderCell)  _
                    
AndAlso (e.TableCellIdentity.Column.Name "Column2")) Then
            
e.Style.CellType "CheckBox"
            
e.Style.CellValueType = GetType(System.Boolean)
            e.Style.CellValue 
CheckBoxValue
            e.Style.
ReadOnly = false
            
e.Style.CellAppearance GridCellAppearance.Raised
            e.Style.Enabled 
= true
            
e.Style.CheckBoxOptions = New GridCheckBoxCellInfo("true""false""indeterminate"false)
            e.Style.Description 
"test"
        
End If
        
        
e.Handled = true
    End Sub




Thanks,
AL.Solai.


FB Felipe Bahiana Almeida November 4, 2015 03:25 PM UTC

I still don't know how to achieve that:

3 - I need a way to have one master checkbox that checks/unchecks them all.

can you help me ?


SA Solai A L Syncfusion Team November 5, 2015 06:19 AM UTC

Hi Felipe,

Thank you for your update.

Please refer the below provided video and sample for reference. In this sample we have achieved both the checkbox description and a master checkbox to check/uncheck.
Video :
http://www.syncfusion.com/downloads/support/forum/61942/ze/checkbox2067518906

Sample :
http://www.syncfusion.com/downloads/support/forum/61942/ze/CS-1461714942

Thanks,
AL.Solai.


FB Felipe Bahiana Almeida November 10, 2015 02:53 PM UTC

I think I did not communicate my scenario so well.
This picture should elucidate this problem.

In my scenario I have many series which I use to show in a table and plot in a chart.
I show each series' values in a grid and, the user have the option to show/hide the in the chart by pressing the checkbox in the header. (same functionality achieved with the legend)
I could not use legend because as the number of columns increased, the legends became messy (one overlapping the others) because of the lack of space.

I need to have a master chebox to check / uncheck all the columns checkboxes, not rows checkboxes like you did.

Thanks for the help

Attachment: CropperCapture[47]_6669ecc.zip


FB Felipe Bahiana Almeida November 10, 2015 08:57 PM UTC

I got it ! 
Thanks for your help


SA Solai A L Syncfusion Team November 11, 2015 06:22 AM UTC

Hi Felipe,

Thank you for your update.

We are glad to know that your issue has been resolved. Please  let us know if you have any other concerns.

Thanks,
AL.Solai.


TR Truong replied to Solai A L December 8, 2016 02:47 AM UTC

Hi Felipe,

Thank you for your update.

If you want to set text for checkbox , you need to use Description  property. Please refer the below code example for reference.

Code Example :

 Private Sub gridGroupingControl1_QueryCellStyleInfo(ByVal sender As ObjectByVal As GridTableCellStyleInfoEventArgs)
        
If ((e.TableCellIdentity.TableCellType GridTableCellType.ColumnHeaderCell)  _
                    
AndAlso (e.TableCellIdentity.Column.Name "Column2")) Then
            
e.Style.CellType "CheckBox"
            
e.Style.CellValueType = GetType(System.Boolean)
            e.Style.CellValue 
CheckBoxValue
            e.Style.
ReadOnly = false
            
e.Style.CellAppearance GridCellAppearance.Raised
            e.Style.Enabled 
= true
            
e.Style.CheckBoxOptions = New GridCheckBoxCellInfo("true""false""indeterminate"false)
            e.Style.Description 
"test"
        
End If
        
        
e.Handled = true
    End Sub




Thanks,
AL.Solai.

How to change the style of header column contain checkbox as same as other column


PM Piruthiviraj Malaimelraj Syncfusion Team December 8, 2016 12:25 PM UTC

Hi Truong, 
 
Thanks for the update. 
 
We have analyzed your scenario. In order to customize the appearance of the check box , you need to customize the GridCheckBoxCellModel and GridCheckBoxCellRenderer. Please make use of the below code, 
 
Code example: 
//Custom CheckBox 
public class GridCustomCheckBoxCellModel : GridCheckBoxCellModel 
{ 
    public GridCustomCheckBoxCellModel(GridModel grid) 
        : base(grid) 
    { 
    } 
    public override GridCellRendererBase CreateRenderer(GridControlBase control) 
    { 
        return new GridCustomCheckBoxCellRenderer(control, this); 
    } 
} 
public class GridCustomCheckBoxCellRenderer : GridCheckBoxCellRenderer 
{ 
    public GridCustomCheckBoxCellRenderer(GridControlBase grid, GridCellModelBase cellModel) 
        : base(grid, cellModel) 
    { 
    } 
    protected override void OnDraw(Graphics g, Rectangle clientRectangle, int rowIndex, int colIndex, GridStyleInfo style) 
    { 
        string text = style.Description; 
        Font font = style.GdipFont; 
        ButtonState state = GetState(rowIndex, colIndex, style); 
        ContentAlignment align = GridUtil.ConvertToContentAlignment(style.HorizontalAlignment) 
            & GridUtil.ConvertToContentAlignment(style.VerticalAlignment); 
 
        bool alignToRight = (style.TextAlign == GridTextAlign.Right) != Grid.IsRightToLeft(); 
        DrawCheckBox(g, clientRectangle, style, state, align, text, font); 
        GridMargins margins = style.ReadOnlyTextMargins.ToMargins(); 
        if (Grid.IsRightToLeft()) 
        { 
            margins = margins.SwapRightToLeft(); 
        } 
 
        Rectangle textRectangle = GridMargins.RemoveMargins(clientRectangle, margins); 
        Rectangle rc = clientRectangle; 
        bool drawPressed = false; 
        GridProperties propertyObject = Grid.Model.Properties; 
        if (colIndex > 0 && (this.Grid.Selections.Ranges.AnyRangeIntersects(GridRangeInfo.Col(colIndex)) 
           || this.CurrentCell.ColIndex.Equals(colIndex)) && this.CurrentCell.IsActive && Grid.MarkColHeader) 
            drawPressed = true; 
        else if (this.CurrentCell.IsActive && Grid.MarkRowHeader && (this.Grid.Selections.Ranges.AnyRangeIntersects(GridRangeInfo.Row(rowIndex)) 
           || this.CurrentCell.RowIndex.Equals(rowIndex))) 
            drawPressed = true; 
        // Draw button look (if not pressed) 
        if (style.CellAppearance == GridCellAppearance.Flat && propertyObject.Buttons3D) 
        { 
            Color shadow = SystemColors.ControlDarkDark; 
 
            if (!Grid.PrintingMode) 
            { 
                if ((style.Themed && XPThemes.IsThemedOS && XPThemes.IsThemeActive && this.Grid.ThemesEnabled) 
                   || ((style.Themed && this.Grid.ThemesEnabled && ((this.Grid.Model.Options.GridVisualStyles != GridVisualStyles.SystemTheme))))) 
                { 
                    Color hoverTextColor = Color.Empty, normalTextColor = Color.Empty, pressedTextColor = Color.Empty; 
                    if (this.Grid.Model.Options.GridVisualStyles == GridVisualStyles.Metro || this.Grid.Model.Options.GridVisualStyles == GridVisualStyles.Office2010Black) 
                        ((IThemeStyle)this.Grid.Model.Options.GridVisualStylesDrawing).GetHeaderTextColors(out normalTextColor, out hoverTextColor, out pressedTextColor); 
                    ThemedHeaderDrawing.HeaderState state1 = ThemedHeaderDrawing.HeaderState.Normal; 
                    GridRangeInfo cellRange = GridRangeInfo.Cell(rowIndex, colIndex); 
                    Point mouseClientPosition = Grid.GetWindow().PointToClient(Control.MousePosition); 
                    if (drawPressed && this.Grid.Model.Properties.MarkRowHeader) 
                        state1 = ThemedHeaderDrawing.HeaderState.Pressed; 
                    else if (drawPressed && this.Grid.Model.Properties.MarkColHeader) 
                        state1 = ThemedHeaderDrawing.HeaderState.Pressed; 
                    if ((this.Grid.Model.Options.GridVisualStyles == GridVisualStyles.Metro || this.Grid.Model.Options.GridVisualStyles == GridVisualStyles.Office2010Black) 
                        && state1 == ThemedHeaderDrawing.HeaderState.Normal) 
                    { 
                        style.TextColor = normalTextColor; 
                    } 
 
                    bool isGroupCaption = this.Grid.Model.Options.GridVisualStyles == GridVisualStyles.Metro && style.CellIdentity.Info.StartsWith("GroupCaptionRow"); 
 
                    Grid.Model.Options.GridVisualStylesDrawing.DrawHeaderStyle(g, rc, state1); 
 
                    if (state1 != ThemedHeaderDrawing.HeaderState.Normal) 
                    { 
                        Grid.NotifyCellHighlighted(rowIndex, colIndex, style); 
                    } 
                } 
            } 
            else 
            { 
                GridBorder border = new GridBorder(GridBorderStyle.Solid, Color.Black); 
                if (style.ReadOnlyBorders.Bottom.Style == GridBorderStyle.None 
                    && propertyObject.DisplayHorzLines) 
                { 
                    GridBorderPaint.DrawRectangle(g, border, clientRectangle, Color.White, GridBorderSide.Bottom); 
                } 
 
                if (style.ReadOnlyBorders.Right.Style == GridBorderStyle.None 
                    && propertyObject.DisplayVertLines) 
                { 
                    GridBorderPaint.DrawRectangle(g, border, clientRectangle, Color.White, GridBorderSide.Right); 
                } 
            } 
        } 
        base.OnDraw(g, clientRectangle, rowIndex, colIndex, style); 
    } 
} 
 
//Add the custom cell type to cell models. 
this.gridGroupingControl1.TableModel.CellModels.Add("CustomCheckBox", new GridCustomCheckBoxCellModel(this.gridGroupingControl1.TableModel)); 
 
 
 
Sample link: 
 
Regards, 
Piruthiviraj

Loader.
Live Chat Icon For mobile
Up arrow icon