How can I get an event to send an argument to a function? So I can have dataGridView1 & dataGridView2 both using the function dataGridView1_MouseMove?
private void dataGridView1_MouseMove(object sender, MouseEventArgs e)
{
if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
{
// If the mouse moves outside the rectangle, start the drag.
if (dragBoxFromMouseDown != Rectangle.Empty &&
!dragBoxFromMouseDown.Contains(e.X, e.Y))
{
// Proceed with the drag and drop, passing in the list item.
DragDropEffects dropEffect = dataGridView1.DoDragDrop(
dataGridView1.Rows[rowIndexFromMouseDown],
DragDropEffects.Move);
}
}
}
I’m currently using this function as well as some others to allow the rows in the dataGridView1 to be dragged and dropped, how can I use this same function for dataGridView2?
If you want to use the same method, you need to never refer to
dataGridView1directly.Instead, change it to use
senderas your DataGridView, like so:Once you’ve done this, you can add the subscription to any number of DataGridView instances, and they’ll all use the same event handler.