如何在DGV上添加右键菜单?

yixian2007 2009-03-19 10:56:33
请问如何在DGV上添加右键菜单?

谢谢.
...全文
111 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Teng_s2000 2009-03-20
  • 打赏
  • 举报
回复
UP
yixian2007 2009-03-20
  • 打赏
  • 举报
回复
成功了,结贴给分.
深海之蓝 2009-03-19
  • 打赏
  • 举报
回复
来晚了,楼上两位正解
PandaIT 2009-03-19
  • 打赏
  • 举报
回复
ContextMenuStrip

快捷菜单

然后去属性里面找Click事件

dell0923 2009-03-19
  • 打赏
  • 举报
回复
画面中追加ContextMenuStrip控件,在DGV的CellMouseClick事件中把ContextMenuStrip显示出来就可以了.

可能还要用到坐标定位,在CellMouseClick事件里
if (e.Button == MouseButtons.Right)
{
if (e.RowIndex >= 0)
{
this.dgvWords.Rows[e.RowIndex].Cells[e.ColumnIndex].Selected = true;
int width = 0;
for (int i = 0; i < e.ColumnIndex; i++)
{
width += this.dgvWords.Columns[i].Width;
}
int height = 0;
for (int i = 0; i < e.RowIndex; i++)
{
height += this.dgvWords.Rows[i].Height;
}
this.cmsDelete.Show(dgvWords.PointToScreen(new Point(e.X + width, e.Y + height)));
}
}
dell0923 2009-03-19
  • 打赏
  • 举报
回复
this.cmsDelete.Show(dgvWords.PointToScreen(new Point(e.X + width, e.Y + height)));

cmsDelete就是ContextMenuStrip
yixian2007 2009-03-19
  • 打赏
  • 举报
回复
this.cmsDelete.Show(dgvWords.PointToScreen(new Point(e.X + width, e.Y + height)));

这个show方法是什么意思?
yixian2007 2009-03-19
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 dell0923 的回复:]
画面中追加ContextMenuStrip控件,在DGV的CellMouseClick事件中把ContextMenuStrip显示出来就可以了.

可能还要用到坐标定位,在CellMouseClick事件里

C# codeif (e.Button == MouseButtons.Right)
{
if (e.RowIndex >= 0)
{
this.dgvWords.Rows[e.RowIndex].Cells[e.ColumnIndex].Selected = true;
int width = 0;

[/Quote]

怎么把ContextMenuStrip显示出来?

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧