Click here to Skip to main content
Click here to Skip to main content

Hide DevExpress AgDataGrid Header MenuItem in Silverlight

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

Introduction

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">
  </dxg:AgDataGrid>
</Grid>
 
Step 2: Add Column into grid and create event for HeaderMenuShowing
 
 <dxg:AgDataGrid.Columns>
      <dxg:AgDataGridColumn  AllowEditing="False"
          FieldName="SignalTime"
          HeaderContent="Signal Time"
          Width="140"
          HeaderMenuShowing="AgDataGridColumn_HeaderMenuShowing" />                
 </dxg:AgDataGridColumn>
 
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;
                }
            }
        }

License

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

Share

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 : http://hirenkhirsaria.blogspot.com/

Comments and Discussions

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