Reputation: 23941
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.
Upvotes: 0
Views: 688
Reputation: 2973
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:
A.Tag = Cell you want to set to A after A is clicked
Private Sub A_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles A.Click
CType(A.Tag, DataGridViewTextBoxCell).Value = "A"
End Sub
Upvotes: 1
Reputation: 9193
Cast the sender argument as the ToolStripItem and then use that object to determine type A or B.
If CType(sender, ToolStripItem).Text = "A" Then 'Or Text of A
'Work to Update Cell
End If
Upvotes: 0