且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

带有上下文菜单的DataGridView?

更新时间:2023-12-06 10:03:04

如果发送方对象的类型不属于您可以用来做到这一点(您可以只在调试器中查看或阅读文档以找出类型),而可以使用鼠标位置,控件应具有一些方法来告诉您某个点上的单元格.
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.