This is a migrated thread and some comments may be shown as answers.

Adding controls to the Group header

16 Answers 369 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sonya
Top achievements
Rank 1
Sonya asked on 15 Sep 2009, 09:51 PM
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!

16 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 16 Sep 2009, 08:50 AM
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.
0
Sonya
Top achievements
Rank 1
answered on 16 Sep 2009, 01:21 PM
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!

 

0
Sonya
Top achievements
Rank 1
answered on 17 Sep 2009, 09:47 PM
Does anyone have any ideas on how to accomplish this?  Thanks!
0
Jack
Telerik team
answered on 18 Sep 2009, 11:08 AM
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.
0
Sonya
Top achievements
Rank 1
answered on 22 Sep 2009, 09:47 PM
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!!
0
Jack
Telerik team
answered on 24 Sep 2009, 06:25 AM
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.
0
Sonya
Top achievements
Rank 1
answered on 03 Nov 2009, 10:31 PM
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!
0
Jack
Telerik team
answered on 04 Nov 2009, 02:17 PM
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.
0
Sonya
Top achievements
Rank 1
answered on 04 Nov 2009, 06:35 PM
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!

0
Jack
Telerik team
answered on 05 Nov 2009, 08:20 AM
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.
0
Me
Top achievements
Rank 1
answered on 23 Jun 2011, 12:15 AM
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 
0
Jack
Telerik team
answered on 28 Jun 2011, 10:44 AM
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.
0
Rishabh
Top achievements
Rank 1
answered on 03 Apr 2012, 08:09 AM
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
0
Nikolay
Telerik team
answered on 03 Apr 2012, 01:56 PM
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 >>
0
Priyanka
Top achievements
Rank 1
answered on 21 Sep 2015, 05:53 AM

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);
        }​

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 21 Sep 2015, 02:01 PM
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
Tags
GridView
Asked by
Sonya
Top achievements
Rank 1
Answers by
Jack
Telerik team
Sonya
Top achievements
Rank 1
Me
Top achievements
Rank 1
Rishabh
Top achievements
Rank 1
Nikolay
Telerik team
Priyanka
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or