I have a WINFORM app with a DataGridView control , hooked into a ContextMenuStrip control.
The ContextMenuStrip fires events to essentially perform copy / paste between the DataGridView and the Clipboard.
private void copyToolStripMenuItem_Click(object sender, EventArgs e)
{
CopyClipboard();
}
private void CopyClipboard()
{
DataObject d = myGrid.GetClipboardContent();
Clipboard.SetDataObject(d);
}
private void pasteCtrlVToolStripMenuItem_Click(object sender, EventArgs e)
{
PasteClipboard();
}
I've added another DataGridView to my application and wish to share ContextMenuStrip between them since, per my code above, it's hardcoded to my grid, myGrid.
I believed it would simply be an easy exercise to modify my code to cast a new DataGridView control from the sender:
private void copyToolStripMenuItem_Click(object sender, EventArgs e)
{
CopyClipboard(sender);
}
private void CopyClipboard(object sender)
{
var grid = (DataGridView)sender;
DataObject d = grid.GetClipboardContent();
Clipboard.SetDataObject(d);
}
private void pasteCtrlVToolStripMenuItem_Click(object sender, EventArgs e)
{
var grid = (DataGridView)sender;
PasteClipboard(grid);
}
but of course, I found that the sender was instead the ToolStripMenuItem.
Is there a way to reference the original DataViewGrid via the sender, or EventArgs e ?
And, thank you for reading :)