Datagridview单元格上下文菜单问题? [英] Datagridview Cell Contextmenustrip Problem?

查看:57
本文介绍了Datagridview单元格上下文菜单问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

在我的Form1中,我有
Datagridview1,Contextmenustrip1.

当我单击任何单元格并单击右键时,我正在显示Contextmenustrip1.

我的问题是我在Datagridview1中有2行5列,
假设我选择Datagridview1.Rows [0] .cell [0]
我右键单击Datagridview1.Rows [1] .cells [4],

表示选定的单元格不同,而右键单击的单元格也不同.

如果选定的单元格和右键单击的单元格都不相同,我不想显示contextmenustrip1.

如果两个都想显示contextmenustrip1.

任何想法或建议将不胜感激.

问候,
Pawan.

Hi All,

In my Form1 i have
Datagridview1,Contextmenustrip1.

when i click on any cell and on Rightclick, i am showing Contextmenustrip1.

My problem is i have 2 rows With 5 Columns in Datagridview1,
suppose if i select Datagridview1.Rows[0].cell[0]
and i right click on Datagridview1.Rows[1].cells[4],

means selected Cell is different and Right Clicked cell is different.

i don''t want to show contextmenustrip1 if both selected and rightclicked cell''s are different.

if both are same want to show contextmenustrip1.

Any idea or suggestion would be really appreciated.

Regards,
Pawan.

推荐答案

您需要做的第一件事就是确保您右键单击的是所选单元格;您可以通过处理gridview上的"CellMouseDown"事件并以编程方式(如
)选择单元格来执行此操作
the first thing you need to do is making sure that what ever you right clicked on is the selected cell; you can do this by handling "CellMouseDown" event on the gridview and select the cell in programmatic fashion like
datagridview1[e.columnindex,e.rowindex].selected=true;



因此,您甚至不需要验证是否右键单击了该单元格并且所选单元格是不同的单元格.

希望对您有帮助
祝你好运



and hence there won''t even be a need for you to validate if the cell right clicked on and the selected one are different cells.

I hope that helped
good luck


这篇关于Datagridview单元格上下文菜单问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆