删除gridview选项

时间:2011-05-09 14:19:10

标签: winforms .net-3.5 devexpress

如何从GridView菜单中删除“按框显示分组”和“删除此列”?当我去参加活动时没有ShowGridMenu事件,所以THIS对我不起作用......

1 个答案:

答案 0 :(得分:5)

为此目的使用GridView.PopupMenuShowing事件。

private void gridView1_PopupMenuShowing(object sender, DevExpress.XtraGrid.Views.Grid.PopupMenuShowingEventArgs e) {
            if(e.MenuType == GridMenuType.Column) 
                RemoveItem(e.Menu, GridLocalizer.Active.GetLocalizedString(GridStringId.MenuColumnRemoveColumn));
            else
                if(e.MenuType == GridMenuType.Group) 
                    RemoveItem(e.Menu, GridLocalizer.Active.GetLocalizedString(GridStringId.MenuGroupPanelShow));
        }

        private void RemoveItem(GridViewMenu menu, string caption) { 
            for(int i = 0; i < menu.Items.Count; i ++)
                if(menu.Items[i].Caption == caption) {
                    menu.Items.RemoveAt(i);
                    break;
                }
        }