【发布时间】:2011-05-04 14:09:43
【问题描述】:
我有一个数据网格视图,我在其中显示有关产品的信息。当用户选择一个单元格然后右键单击该单元格时,我想绑定一个上下文菜单。我有另一个上下文菜单,它绑定到 datagridview 的列。如果用户右键单击列,则会显示上下文菜单。
我试过这样,但它不起作用。当用户右键单击单元格时,上下文菜单会显示,但绑定到列标题的上下文菜单不起作用。
private void GridView1_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
productContextMenu.Show(GridView1, e.Location);
}
}
如何做到让用户右击datagridview时显示出来?
提前感谢。
编辑
谢谢你的答案。我解决了这样的问题:
private void GridView1_MouseUp(object sender, MouseEventArgs e)
{
DataGridView.HitTestInfo hitTestInfo;
if (e.Button == MouseButtons.Right)
{
hitTestInfo = GridView1.HitTest(e.X, e.Y);
if (hitTestInfo.Type == DataGridViewHitTestType.Cell)
{
productContextMenu.Show(GridView1, e.Location);
}
}
}
两个上下文菜单都显示。当我单击上下文菜单显示的列时,以及单击上下文菜单显示的单元格时。
【问题讨论】:
-
感谢您知道您得到了答复 :)
-
如果你得到了他的想法的解决方案,你为什么不标记为答案
标签: c# datagridview contextmenu