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.
Unfortunately, activation email could not send to your email. Please try again.

Checkbox in column header in GridGroupingControl

Thread ID:

Created:

Updated:

Platform:

Replies:

61942 Jun 5,2007 04:58 AM Dec 8,2016 07:25 AM Windows Forms 25
loading
Tags: GridControl
rewf
Asked On June 5, 2007 04:58 AM

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

haneefm [Syncfusion]
Replied On June 5, 2007 02:09 PM

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

rewf
Replied On June 7, 2007 06:42 AM

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

Jeba S [Syncfusion]
Replied On June 8, 2007 07:19 AM

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.

rewf
Replied On June 8, 2007 09:19 AM

Sorry, Can you help me with some code

Rajagopal [Syncfusion]
Replied On June 8, 2007 08:26 PM

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

rewf
Replied On June 18, 2007 09:25 AM

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

haneefm [Syncfusion]
Replied On June 18, 2007 02:03 PM

Hi Faisal,

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

Best regards,
Haneef

rewf
Replied On June 21, 2007 04:36 AM

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

haneefm [Syncfusion]
Replied On June 21, 2007 06:49 PM

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

rewf
Replied On June 22, 2007 02:44 AM

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

rewf
Replied On July 2, 2007 11:37 AM

Hanif,

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

Thanks.
Faisal Iqbal

haneefm [Syncfusion]
Replied On July 2, 2007 04:34 PM

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

rewf
Replied On July 2, 2007 07:47 PM

Yes Hanif,

Yes this what I needed. Thanks a lot.

Regards,
Faisal Iqbal

Felipe Bahiana Almeida
Replied On October 28, 2015 02:35 PM

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

Solai A L [Syncfusion]
Replied On October 29, 2015 05:07 AM

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.

Felipe Bahiana Almeida
Replied On October 29, 2015 08:36 AM

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 ?

Felipe Bahiana Almeida
Replied On October 29, 2015 09:55 AM

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

Solai A L [Syncfusion]
Replied On October 30, 2015 04:44 AM

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.

Felipe Bahiana Almeida
Replied On November 4, 2015 10:25 AM

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 ?

Solai A L [Syncfusion]
Replied On November 5, 2015 01:19 AM

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.

Felipe Bahiana Almeida
Replied On November 10, 2015 09:53 AM

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

Felipe Bahiana Almeida
Replied On November 10, 2015 03:57 PM

I got it ! 
Thanks for your help

Solai A L [Syncfusion]
Replied On November 11, 2015 01:22 AM

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.

Truong
Replied On December 7, 2016 09:47 PM

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

Piruthiviraj Malaimelraj [Syncfusion]
Replied On December 8, 2016 07:25 AM

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

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.

;