Click here to Skip to main content
12,399,471 members (58,915 online)
Click here to Skip to main content
Add your own
alternative version

Stats

17K views
Posted

Hide DevExpress AgDataGrid Header MenuItem in Silverlight

, 25 Dec 2011 CPOL
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 7+ years of Experience in Microsoft.Net Environment.

Major Development Skills are : WPF, Silverlight, Windows Mobile, WCF RIA Service, C#, Sql Server & ASP.Net

Follow him on : http://hirenkhirsaria.blogspot.com/

You may also be interested in...

Comments and Discussions

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