Dev GirdView 去掉系统菜单增加自定义菜单

Dev GirdView 去掉系统菜单增加自定义菜单

1.获取gridview 事件如下:

 private void gridView1_PopupMenuShowing(object sender, DevExpress.XtraGrid.Views.Grid.PopupMenuShowingEventArgs e)
        {
            if (e.MenuType == DevExpress.XtraGrid.Views.Grid.GridMenuType.Column)//判断是否是列标题的右键菜单
            {
                GridViewColumnMenu menu = e.Menu as GridViewColumnMenu;
                //menu.Items.RemoveAt(6);//移除右键菜单中的第7个功能,从0开始
                menu.Items.Clear();//清除所有功能
                 string strDisp =自己需要增加的右键信息

                 DXMenuItem dxm = new DXMenuItem();
                  dxm.Caption = strDisp;
                  menu.Items.Add(dxm);                 
            }
        }

2.红色标示第一行清除dev自带的右键系统菜单。

3.红色标示第二行增加自己定义的菜单,可以读取lst 或者datatable 数据集进行赋值。

4.声明DXMenuItem dxm = new DXMenuItem();
5.赋值   dxm.Caption = strDisp;
6.增加自定义数据集 menu.Items.Add(dxm);                 

 

7.触发右键菜单

 private void gridView1_MouseUp(object sender, MouseEventArgs e)
        {
            DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo hi = this.gridView1.CalcHitInfo(e.Location);
            if (e.Button == MouseButtons.Right)
            {
                this.popupMenu1.ShowPopup(Control.MousePosition);
            }
        }

你可能感兴趣的:(dev,自定义菜单,GirdView,系统菜单)