Group property null for GridColumnGroupCellElement

3 posts, 1 answers
  1. Tim Weckx
    Tim Weckx avatar
    4 posts
    Member since:
    Mar 2010

    Posted 25 Mar 2010 Link to this post

    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. Answer
    Jack
    Admin
    Jack avatar
    2333 posts

    Posted 29 Mar 2010 Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Tim Weckx
    Tim Weckx avatar
    4 posts
    Member since:
    Mar 2010

    Posted 29 Mar 2010 Link to this post

    Jack,

    That worked great, thank you.
Back to Top