Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Posted

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.
 
Share this answer
 
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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900