I’ve got a dynamically filled datagrid view. When a user right clicks a cell in the datagridview, it opens a context menu, located by that cell. The context menu has two choices: A and B. I want to set the value of the cell to A if they pick A, and B if they pick B.
I guess ideally, I would like to pass the relevant cell as a field in the event args passed to ContextMenu’s ToolStripItem.click. So the handler for ToolStripItem A’s click event would read the relevant cell from the event args and set it to A , like this…
Private Sub A_Click(ByVal sender As System.Object, ByVal e As Customized System.EventArgs) Handles A.Click
e.relevantCell.Value=A
End Sub
But I can’t figure out how to pass a custom event arg. Or if there is some easier way to do this? I can’t just use the X and Y coordinates, because the context menu/mouse won’t necessary by over the relevant cell.
May be you can put the desired cell in the Tag property (which accepts objects), then at menu item click, get the cell from the tag and set it’s value
Try: