Remove a column permanently from the HeaderMenu context menu.

3 posts, 0 answers
  1. Lakshmi Narayanan
    Lakshmi Narayanan avatar
    2 posts
    Member since:
    Jun 2014

    Posted 16 Jun 2014 Link to this post

    With GridViewHeaderMenu.IsEnabled="true" settings, I always get all the columns in the context-menu at right click of header for hide/show. But I would want, not to display a column that I am keeping visible=false always. How to do that. Your help would be greatly appreciated.
  2. Lakshmi Narayanan
    Lakshmi Narayanan avatar
    2 posts
    Member since:
    Jun 2014

    Posted 17 Jun 2014 in reply to Lakshmi Narayanan Link to this post

    Hi Telerik team, is there any help out there? Finger crossed!
  3. UI for WPF is Visual Studio 2017 Ready
  4. Yoan
    Admin
    Yoan avatar
    1070 posts

    Posted 19 Jun 2014 Link to this post

    Hi,

    You can exclude the invisible columns like so:
     
                                 .
                                 .
    item = new RadMenuItem();
                    item.Header = "Choose Columns:";
                    menu.Items.Add(item);
     
                    // create menu items
                    foreach (GridViewColumn column in grid.Columns)
                    {
                        if (column.IsVisible)
                        {
                            RadMenuItem subMenu = new RadMenuItem();
                            subMenu.Header = column.Header;
                            subMenu.IsCheckable = true;
                            subMenu.IsChecked = true;
     
                            Binding isCheckedBinding = new Binding("IsVisible");
                            isCheckedBinding.Mode = BindingMode.TwoWay;
                            isCheckedBinding.Source = column;
     
                            // bind IsChecked menu item property to IsVisible column property
                            subMenu.SetBinding(RadMenuItem.IsCheckedProperty, isCheckedBinding);
     
                            item.Items.Add(subMenu);
                        }                 
                    }
                }
                else
                {
                    menu.IsOpen = false;
                }
                                 .
                                 .

    I hope this helps.

    Regards,
    Yoan
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top