Adding controls to the Group header

17 posts, 0 answers
  1. Sonya
    Sonya avatar
    8 posts
    Member since:
    Sep 2009

    Posted 15 Sep 2009 Link to this post

    Is it possible to add controls to the group header row?  For instance, if I wanted to group my rows by a certain field, and add a combo box to each group's header row whose value affects all the rows in the group, is that possible?  Thanks!
  2. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 16 Sep 2009 Link to this post

    Hi Sonya Lang,

    Yes, this is possible. Please look at the following KB article - it describes how to add a checkbox element inside GridHeaderCellElement. You should add RadComboBoxElement instead. If you want to use the combobox control (which is not preferred), you should host it inside RadHostItem.

    Greetings,
    Jack
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Sonya
    Sonya avatar
    8 posts
    Member since:
    Sep 2009

    Posted 16 Sep 2009 Link to this post

    That example works for the table header, but when I switch it to use the group header, I get an 'Object not set to an instance of object' error.  The error occurs on the if statement line in this code:

    Private

     

    Sub radgridView1_CreateCell(ByVal sender As Object, ByVal e As GridViewCreateCellEventArgs) Handles radgridView1.CreateCell

     

     

    If TypeOf e.Row Is GridGroupHeaderRowElement AndAlso e.Column.Equals(Me.radgridView1.Columns(1)) Then

     

    e.CellElement =

    New GroupHeaderComboBox(e.Column, e.Row, bsFactors)

     

     

    End If

     

     

    End Sub

    I think this is due to the column collection in the Group Header row being different than the table header.  How can I work around this?  Thanks!

     

  5. Sonya
    Sonya avatar
    8 posts
    Member since:
    Sep 2009

    Posted 17 Sep 2009 Link to this post

    Does anyone have any ideas on how to accomplish this?  Thanks!
  6. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 18 Sep 2009 Link to this post

    Hi Sonya Lang,

    Yes, you are correct. Group header row is a system row that has no representation in the underlying data source, and it affects cells differently. For example it contains only one cell of type GridCellElement. So, you should not access the column index, but the column type. Here is a sample:

    Private Sub radGridView1_CreateCell(ByVal sender As ObjectByVal e As GridViewCreateCellEventArgs) 
        If e.CellType Is GetType(GridCellElement) AndAlso TypeOf e.Row Is GridGroupHeaderRowElement Then 
            e.CellType = GetType(CustomGroupHeaderCellElement) 
        End If 
    End Sub 

    I prepared also a sample combobox cell element. Please take a look:

    Public Class CustomGroupHeaderCellElement 
        Inherits GridCellElement 
        Private comboBox As RadComboBoxElement 
         
        Public Sub New(ByVal column As GridViewColumn, ByVal row As GridRowElement) 
            MyBase.New(column, row) 
             
        End Sub 
         
        Protected Overloads Overrides Sub CreateChildElements() 
            MyBase.CreateChildElements() 
            comboBox = New RadComboBoxElement() 
            comboBox.MinSize = New Size(100, 20) 
            comboBox.Items.Add(New RadComboBoxItem("Item 1")) 
            comboBox.Items.Add(New RadComboBoxItem("Item 2")) 
            comboBox.Items.Add(New RadComboBoxItem("Item 3")) 
            Me.Children.Add(comboBox) 
            ApplyThemeToElement(comboBox, "Vista"
        End Sub 
         
        Protected Overloads Overrides Function ArrangeOverride(ByVal finalSize As SizeF) As SizeF 
            Dim size As SizeF = MyBase.ArrangeOverride(finalSize) 
            Dim rect As RectangleF = GetClientRectangle(finalSize) 
            If Me.comboBox IsNot Nothing Then 
                Me.comboBox.Arrange(New RectangleF(rect.Right - Me.comboBox.DesiredSize.Width - 5, rect.Top + (rect.Height - comboBox.DesiredSize.Height) / 2, Me.comboBox.DesiredSize.Width, comboBox.DesiredSize.Height)) 
            End If 
            Return size 
        End Function 
         
        Private Sub ApplyThemeToElement(ByVal item As RadItem, ByVal themeName As String
            Dim builder As DefaultStyleBuilder = TryCast(ThemeResolutionService.GetStyleSheetBuilder(DirectCast(item.ElementTree.Control, RadControl), item.GetThemeEffectiveType().FullName, String.Empty, themeName), DefaultStyleBuilder) 
            If builder IsNot Nothing Then 
                item.Style = builder.Style 
            End If 
        End Sub 
    End Class 
     

    I hope this helps. If you need further assistance, I will be glad to help.

    Greetings,
    Jack
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. Sonya
    Sonya avatar
    8 posts
    Member since:
    Sep 2009

    Posted 22 Sep 2009 Link to this post

    I have been able to use this code successfully to add the combo box.  In addition I would like to be able to process the rows in the selected group when a combo box is changed.  In other words, if a combo box for a group is changed, I want to access the rows in that group alone, not the other groups.  I have already added a handler for the SelectedindexChanged event to the class.  How can I do this?  Thanks!!
  8. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 24 Sep 2009 Link to this post

    Hello Sonya,

    Thank you for writing me back.

    You can use the Group property of the GridViewGroupRowInfo that owns your cell. It contains a Rows collection with all rows that belong to the group. Please consider the sample below:

    Private Sub comboBox_SelectedIndexChanged(ByVal sender As ObjectByVal e As EventArgs) 
        Dim groupRow As GridViewGroupRowInfo = DirectCast(Me.RowInfo, GridViewGroupRowInfo) 
        For Each row As GridViewDataRowInfo In groupRow.Group.Rows 
            '... 
        Next 
    End Sub 

    Should you have any further questions, don't hesitate to contact us.

    Greetings,
    Jack
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  9. Sonya
    Sonya avatar
    8 posts
    Member since:
    Sep 2009

    Posted 03 Nov 2009 Link to this post

    How would I go about selectively applying this combobox element to the group header rows?  I have three levels of grouping, and I do not want to add the combobox to the topmost group level.  How can I identify the topmost group in the CreateCell event?  Thanks!
  10. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 04 Nov 2009 Link to this post

    Hi Sonya,

    You should check whether the group parent is the root group of MasterGridViewTemplate. Check the sample below:

    if (groupRow.Group.Parent = Me.radGridView1.MasterGridViewTemplate.Root)
    {
        '...
    }

    Please contact me if you need further assistance with this.

    All the best,
    Jack
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  11. Sonya
    Sonya avatar
    8 posts
    Member since:
    Sep 2009

    Posted 04 Nov 2009 Link to this post

    I couldn't quite get that to work (I cast e.row.rowinfo as a GridViewGroupRowInfo for groupRow), since groupRow.group.parent didn't exist, but I did get it to work by checking the level:

    (in the CreateCell event)

     

     

    Dim groupRow As GridViewGroupRowInfo = CType(e.Row.RowInfo, GridViewGroupRowInfo)  
    If groupRow.Group.Level > 2 Then  
    ...      
    End If  
     
     

    Let me know if you see any problems with this.  Thanks!

  12. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 05 Nov 2009 Link to this post

    Hi Sonya,

    It was my mistake. I tested the case with our latest release - Q3 2009. The Parent property is available only in this version of RadControls. However, using the Level property is a good idea. If you have any other questions, please write me back.

    All the best,
    Jack
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  13. Me
    Me avatar
    1 posts
    Member since:
    May 2011

    Posted 22 Jun 2011 Link to this post

    The link to he post is dead
    I need to add Checkbox to group header.
     iwas able to do so, altering the code you provided to inherit from

    GridGroupContentCellElement

     class
    but, the checkbox is appearing on the rifht most side and also i cannot attach to its check state toggle event.

    Thank you in advance for your help 
  14. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 28 Jun 2011 Link to this post

    Hi Me,

    Thank you for contacting us.

    Yes, using a custom GridGroupContentCellElement is the correct way for implementing this scenario. Please send me your project and I will optimize it. You can find additional information in this KB article.

    Please note that you have to open a new support ticket in order to be able to attach your files.

    I will be glad to help further and I am looking forward to your project.
     
    Kind regards,
    Jack
    the Telerik team
    Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
  15. Rishabh
    Rishabh avatar
    10 posts
    Member since:
    Jun 2012

    Posted 03 Apr 2012 Link to this post

    Hi
    The Link(KB article) you have mentioned is not working.Can you share some other project or link where checkbox is adding to group header.


    Regards
  16. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 03 Apr 2012 Link to this post

    Hello Rishabh,

    The link to the article is now correct. You should be able to navigate to it without any issues.

    Let us know if you have additional questions.

    Kind regards,
    Nikolay
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  17. Priyanka
    Priyanka avatar
    1 posts
    Member since:
    Sep 2015

    Posted 21 Sep 2015 Link to this post

    Hi,

    I have added checkBox in Grid GroupHeader but i am not able to assign the text to that chekbox.

    I have did code as below whicch is working ,but i want to assign text at time of creation of "GridViewColumnGroup".

    protected override void CreateChildElements()
            {
                base.CreateChildElements();
                checkbox = new RadCheckBoxElement();
                checkbox.Text = "testing.....";
                checkbox.CheckAlignment = ContentAlignment.MiddleLeft;
                checkbox.ToggleStateChanged += new StateChangedEventHandler(checkbox_ToggleStateChanged);
                this.Children.Add(checkbox);
            }​

  18. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 21 Sep 2015 Link to this post

    Hello Priyanka,

    Thank you for writing.
     
    Here is a sample code snippet demonstrating how to create a custom group cell containing a RadCheckBoxElement with text:
    private void radGridView1_CreateCell(object sender, Telerik.WinControls.UI.GridViewCreateCellEventArgs e)
    {
        if (e.CellType == typeof(GridGroupContentCellElement))
        {
            e.CellElement = new CustomGridGroupContentCellElement(e.Column, e.Row);
        }
    }
     
    public class CustomGridGroupContentCellElement : GridGroupContentCellElement
    {
        public CustomGridGroupContentCellElement(GridViewColumn column, GridRowElement row) : base(column, row)
        {
        }
     
        protected override Type ThemeEffectiveType    
        {
            get   
            {
                return typeof(GridGroupContentCellElement);    
            }
        }
     
        RadCheckBoxElement checkbox;
        LightVisualElement groupInfo;
        DockLayoutPanel container;
         
        protected override void CreateChildElements()
        {
            base.CreateChildElements();
            container = new DockLayoutPanel();
            groupInfo = new LightVisualElement();
            checkbox = new RadCheckBoxElement();
            checkbox.Text = "check-box text.....";
            checkbox.CheckAlignment = ContentAlignment.MiddleLeft;
            checkbox.ToggleStateChanged += new StateChangedEventHandler(checkbox_ToggleStateChanged);
            container.Children.Add(checkbox);
            container.Children.Add(groupInfo);
            container.LastChildFill = true;
            groupInfo.TextAlignment = ContentAlignment.MiddleLeft;
            this.Children.Add(container);
        }
     
        public override void SetContent()
        {
            base.SetContent();
            this.Text = string.Empty;
            groupInfo.Text = this.RowInfo.Group.Header;
        }
     
        private void checkbox_ToggleStateChanged(object sender, StateChangedEventArgs args)
        {
        }
    }

    I hope this information helps. Should you have further questions I would be glad to help.
     
    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WinForms is Visual Studio 2017 Ready