带有上下文菜单的DataGridView? [英] DataGridView with context menu?

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

问题描述

好,
我在表单上有一个datagridview. datagridview不是数据绑定的.
对于某些单元格,我创建了一个简单的上下文菜单.

我要基于用户从上下文菜单中激活方法的单元格进行操作,我想说要修改该单元格中的文本.

我如何使用传递到上下文菜单方法的发送方对象来标识要修改的单元格?

Ok,
I have a datagridview on a form. The datagridview isn''t data bound.
For some of the cells I have created a simple context menu.

What I want to do is based on the cell where the user activated a method from the context menu, I want to let''s say modify the text inside that cell.

How can I use the sender object passed to the method of the context menu to identify which cell to modify?

推荐答案

如果发送方对象的类型不属于您可以用来做到这一点(您可以只在调试器中查看或阅读文档以找出类型),而可以使用鼠标位置,控件应具有一些方法来告诉您某个点上的单元格.
If the sender object is not of a type that you can use to do that ( you can just look in the debugger or read the docs to find out the type ), you can use the mouse position instead, the control should have methods to tell you the cell over a point.


通过处理上下文菜单的Opened事件,您可以获取对DataGridView的引用.参见 [ [
By handling the Opened event for the context menu you can get a reference to your DataGridView. See this [^] for an example.

Once you have the reference the CurrentCell property might prove useful.

After reading further down my search list I found this[^], which seems to have a more elegant way to get the DataGridView reference. The CurrentCell property still applies, once you have it.


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

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