C# Devexpress数据网格和表单上下文菜单

C# Devexpress数据网格和表单上下文菜单,c#,winforms,devexpress,contextmenustrip,C#,Winforms,Devexpress,Contextmenustrip,当我右键单击网格行时,它会显示分配给它的上下文菜单条几秒钟,然后用窗体的上下文菜单替换它。如果单击位于网格上,如何确保网格的上下文菜单条保持可见 代码: 以下是可能的解决方案: void Form1_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.Columns.Add("Test", typeof(string)); dt.Rows.Add("A"); dt.Rows.A

当我右键单击网格行时,它会显示分配给它的上下文菜单条几秒钟,然后用窗体的上下文菜单替换它。如果单击位于网格上,如何确保网格的上下文菜单条保持可见

代码:


以下是可能的解决方案:

void Form1_Load(object sender, EventArgs e) {
    DataTable dt = new DataTable();
    dt.Columns.Add("Test", typeof(string));
    dt.Rows.Add("A");
    dt.Rows.Add("A");
    dt.Rows.Add("A");
    dt.Rows.Add("A");
    dt.Rows.Add("A");
    dt.Rows.Add("A");
    gridControl1.DataSource = dt;

    ContextMenuStrip ctsForm = new ContextMenuStrip();
    ctsForm.Items.Add("Form");
    ctsForm.Opening += ctsForm_Opening;
    this.ContextMenuStrip = ctsForm;

    ContextMenuStrip ctsGrid = new ContextMenuStrip();
    ctsGrid.Items.Add("Grid Row!");
    ctsGrid.Opening += ctsGrid_Opening;
    gridControl1.ContextMenuStrip = ctsGrid;

    // gridView1.PopupMenuShowing removed at all
}
void ctsGrid_Opening(object sender, System.ComponentModel.CancelEventArgs e) {
    e.Cancel = !IsPointInGridRow(gridView1, gridControl1.PointToClient(Control.MousePosition));
}
void ctsForm_Opening(object sender, System.ComponentModel.CancelEventArgs e) {
   // some code
}
static bool IsPointInGridRow(GridView view, Point pt) {
    return view.CalcHitInfo(pt).InRow;
}

以下是可能的解决方案:

void Form1_Load(object sender, EventArgs e) {
    DataTable dt = new DataTable();
    dt.Columns.Add("Test", typeof(string));
    dt.Rows.Add("A");
    dt.Rows.Add("A");
    dt.Rows.Add("A");
    dt.Rows.Add("A");
    dt.Rows.Add("A");
    dt.Rows.Add("A");
    gridControl1.DataSource = dt;

    ContextMenuStrip ctsForm = new ContextMenuStrip();
    ctsForm.Items.Add("Form");
    ctsForm.Opening += ctsForm_Opening;
    this.ContextMenuStrip = ctsForm;

    ContextMenuStrip ctsGrid = new ContextMenuStrip();
    ctsGrid.Items.Add("Grid Row!");
    ctsGrid.Opening += ctsGrid_Opening;
    gridControl1.ContextMenuStrip = ctsGrid;

    // gridView1.PopupMenuShowing removed at all
}
void ctsGrid_Opening(object sender, System.ComponentModel.CancelEventArgs e) {
    e.Cancel = !IsPointInGridRow(gridView1, gridControl1.PointToClient(Control.MousePosition));
}
void ctsForm_Opening(object sender, System.ComponentModel.CancelEventArgs e) {
   // some code
}
static bool IsPointInGridRow(GridView view, Point pt) {
    return view.CalcHitInfo(pt).InRow;
}

WPF?WinForms?ASP.Net?它是winform抱歉忘了提及无法重现您的问题。是您自己的ContextMenuStrip在表单上正在升级还是LayoutControl中的标准ContextMenu或其他内容?我自己的ContextMenuStrip分配给form@RahulVasantraoKamble:将以下行添加到Form_Load()方法中应该可以消除该问题:
gridControl1.ContextMenuStrip=ctsGridWPF?WinForms?ASP.Net?它是winform抱歉忘了提及无法重现您的问题。是您自己的ContextMenuStrip在表单上正在升级还是LayoutControl中的标准ContextMenu或其他内容?我自己的ContextMenuStrip分配给form@RahulVasantraoKamble:将以下行添加到Form_Load()方法中应该可以消除该问题:
gridControl1.ContextMenuStrip=ctsGrid如果我想继续只将ctsGrid分配给view而不分配给grid控件,您可以提出任何建议吗?@RahulVasantraoKamble view不是控件,因此您无法将ContextMenuStrip分配给gridView。无论如何,我建议您重写视图的嵌入式菜单,而不是使用带有网格控件的ContextMenuStrip。要覆盖视图的上下文菜单,请使用PopupMenuShow事件。要了解更多信息,请查看,如果我想继续将ctsGrid分配给view only而不是grid control,您可以提出任何建议吗?@RahulVasantraoKamble view不是控件,因此您无法将ContextMenuStrip分配给gridView。无论如何,我建议您重写视图的嵌入式菜单,而不是使用带有网格控件的ContextMenuStrip。要覆盖视图的上下文菜单,请使用PopupMenuShow事件。要了解更多信息,请查看