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

Remove a column permanently from the HeaderMenu context menu.

2 Answers 15 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Lakshmi Narayanan
Top achievements
Rank 1
Lakshmi Narayanan asked on 16 Jun 2014, 06:48 PM
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 Answers, 1 is accepted

Sort by
0
Lakshmi Narayanan
Top achievements
Rank 1
answered on 17 Jun 2014, 03:11 PM
Hi Telerik team, is there any help out there? Finger crossed!
0
Yoan
Telerik team
answered on 19 Jun 2014, 12:00 PM
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.
 
Tags
ContextMenu
Asked by
Lakshmi Narayanan
Top achievements
Rank 1
Answers by
Lakshmi Narayanan
Top achievements
Rank 1
Yoan
Telerik team
Share this question
or