This is a migrated thread and some comments may be shown as answers.
Group property null for GridColumnGroupCellElement
2 Answers 31 Views
This is a migrated thread and some comments may be shown as answers.
Tim Weckx
Top achievements
Rank 1
Tim Weckx asked on 25 Mar 2010, 08:07 PM
I'm trying to add some a custom menu item when the user clicks on a GridColumnGroupCellElement to hide all columns below this group. However, the Group property of the GridColumnGroupCellElement is always null and the ColumnIndex is -1. Is there any way to determine the GridViewColumn or GroupViewColumnGroup that this element belongs to?

This is the code i'm currently using

private void Grid_ContextMenuOpening(object sender, Telerik.WinControls.UI.ContextMenuOpeningEventArgs e)  
{  
    if (e.ContextMenuProvider.GetType() == typeof(GridColumnGroupCellElement))  
    {  
        GridColumnGroupCellElement element = (GridColumnGroupCellElement)e.ContextMenuProvider;  
        GridViewColumnGroup group = element.Group; // this is always null  
 
        RadMenuItem customItem = new RadMenuItem("Hide Group""HideGroup");  
        customItem.Tag = group;  
        customItem.Click += new EventHandler(Grid_ContextMenu_HideGroup_Click);  
        e.ContextMenu.Items.Add(customItem);  
    }  

Thank you,
Tim


2 Answers, 1 is accepted

Sort by
0
Accepted
Jack
Telerik team
answered on 29 Mar 2010, 02:37 PM
Hi Tim Weckx,

You can use the ColumnInfo property to get the group. Here is a sample:
 

void radGridView1_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
{
    if (e.ContextMenuProvider.GetType() == typeof(GridColumnGroupCellElement))
    {
        GridColumnGroupCellElement element = (GridColumnGroupCellElement)e.ContextMenuProvider;
        GridViewColumnGroup group = ((GridViewGroupColumn)element.ColumnInfo).Group;
 
        RadMenuItem customItem = new RadMenuItem("Hide Group", "HideGroup");
        customItem.Tag = group;
        customItem.Click += new EventHandler(Grid_ContextMenu_HideGroup_Click);
        e.ContextMenu.Items.Add(customItem);
    }
}

I hope it helps.

Kind regards,
Jack
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
0
Tim Weckx
Top achievements
Rank 1
answered on 29 Mar 2010, 09:34 PM
Jack,

That worked great, thank you.
Asked by
Tim Weckx
Top achievements
Rank 1
Answers by
Jack
Telerik team
Tim Weckx
Top achievements
Rank 1
Share this question
or