2011-05-09 138 views
2

如何從GridView菜單中刪除「Show Group By Box」和「Remove This Column」?當我參加活動時,沒有ShowGridMenu事件,因此THIS不適用於我...刪除gridview選項

回答

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; 
       } 
     } 
+0

添加了一個代碼,顯示如何做到這一點 – 2011-05-09 14:35:04

+0

謝謝,非常有幫助!你應該刪除你網站上的一些過時的答案,他們可能會令人困惑。 – TheGateKeeper 2012-04-15 17:41:29