VS2019 .NET 4.62
I couldn’t figure out all of the examples and finally horsed my way to a working solution.
But, surely, there is a better way to do this?
When I use a delegate in other modes I am able to add parameters, here I couldn’t?
Ex:
btnAddFrom.Click += delegate (object sender, EventArgs e) { add_TransAcctName(sender, e, lstFrom, txtFrom); };
btnAddTo.Click += delegate (object sender, EventArgs e) { add_TransAcctName(sender, e, lstTo, txtTo); };
So, I’ve got to wonder what am I missing where I can’t append rowIndex and ColIndex and not have to use a global variable.
// Required until I learn how to pass within the delegate
int rowIndex = 0;
int colIndex = 0;
private void dgvStatement_MouseClick(object sender, MouseEventArgs e)
{ // ####### A Context menu Strip does not easily allow for recognizing Row and Column #######
rowIndex = dgvStatement.HitTest(e.X, e.Y).RowIndex;
colIndex = dgvStatement.HitTest(e.X, e.Y).ColumnIndex;
// Test for Right Mouse Click
if (e.Button == MouseButtons.Right)
{
// Create a Context menu cm
ContextMenu cm = new ContextMenu();
// Give it a name
cm.Name = "Data Grid View Opions";
// Create a Named Menu Item, reqired for creating the delegate
MenuItem m0 = new MenuItem("Move Columns Right");
//Add to the Context menu list
cm.MenuItems.Add(m0 = new MenuItem("Move Columns Right"));
// Add the Delegate object sender & EventArgs e are included by default
m0.Click += new EventHandler(dgv_MoveColRight);
// Show the context menu
cm.Show(dgvStatement, new Point(e.X, e.Y));
}
}
// Note: No Click in function Name
private void dgv_MoveColRight(object sender, EventArgs e)
{
showMe.Comment = "dgv_MoveColRight";
showMe.Comment = e.ToString();
showMe.Comment = sender.ToString();
showMe.Comment = "Row: " + rowIndex;
showMe.Comment = "Col: " + colIndex;
}
showMe.Comment is a troubleshooting form with a list to display various “stuff” while learning.