使用一个具有多个网格的上下文菜单条

时间:2013-09-11 21:00:50

标签: c# winforms devexpress

我在表单上使用多个xtragrids,并希望在这些网格上使用带有删除功能的单个上下文菜单条。我想处理上下文菜单的click事件:

private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GridView view = sender as GridView;
            {



            }
        }

尝试了这段代码,但由于某种原因,我无法从发件人那里获取数据。很有可能知道单击菜单的哪个网格,所以我可以从点击的网格中删除该行?

1 个答案:

答案 0 :(得分:1)

您可以使用ContextMenuStrip.SourceControl访问控件弹出Context menu,当然,当您右键点击网格时,SourceControl将成为您的网格:

private void deleteToolStripMenuItem_Click(object sender, EventArgs e){
  GridView view = contextMenuStrip1.SourceControl as GridView;//Not sure if it's GridView or GridControl, you may want to try it yourself (I'm not familiar with DevExpress)
  //....
  //....
}