Click here to Skip to main content
11,484,162 members (72,757 online)
Click here to Skip to main content

Hide DevExpress AgDataGrid Header MenuItem in Silverlight

, 25 Dec 2011 CPOL 16.2K
Rate this:
Please Sign up or sign in to vote.


DevExpress AgDatagrid has some good features like grouping column, filter column, columnchooser, etc.

Sometimes, we need to hide some of the menu items of AgDataGrid header.

Let's start how to hide AgDataGrid coloumn header menu item.

Step 1: Drag and Drop DataGrid into XAML page from DevExpress ToolBox.

<Grid x:Name="LayoutRoot">
         <dxg:AgDataGrid    FocusMode="Row">

Step 2: Add Column into grid and create event for HeaderMenuShowing

      <dxg:AgDataGridColumn  AllowEditing="False"
          HeaderContent="Signal Time"
          HeaderMenuShowing="AgDataGridColumn_HeaderMenuShowing" />                

You have to create event handler for each datagrid column for which you don't want menu items.

Step 3: In code behind (C#), write code to hide unwanted header menu items.

private void AgDataGridColumn_HeaderMenuShowing(object sender, ShowContextMenuEventArgs e)
            int cnt = 0;
            var v = e.Menu.Items as ItemCollection;
            foreach (var d in v)
                if (d.GetType() == typeof(AgMenuItem))
                    AgMenuItem myItem = d as AgMenuItem;
                    if (myItem.Header.ToString() == "Show Group Box" || 
myItem.Header.ToString() == "Remove This Column" || myItem.Header.ToString() == "Show Column Chooser")
                        myItem.Visibility = Visibility.Collapsed;
                        if (myItem.Header.ToString() == "Show Column Chooser")
                            cnt = 1;
                if (d.GetType() == typeof(AgMenuSeparator) && cnt == 1)
                    (d as AgMenuSeparator).Visibility = Visibility.Collapsed;
                    cnt = 0;


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Hiren Khirsaria
Software Developer (Senior)
India India
has Total 5+ years of Experience in Microsoft.Net Environment. out of that,

2 + year of Excperience in .Net Development with C# and SQL Server 2005/2008.

3 + years of Experience in WPF/Silverlight.

Current area of Development in Mono for Android (Xamarin), Silverlight/ WPF and Windows Phone 7 Application.

Follow him on :

Comments and Discussions

-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150520.1 | Last Updated 25 Dec 2011
Article Copyright 2011 by Hiren Khirsaria
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid