Click here to Skip to main content
14,267,806 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

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.
   
v2

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100