C# Programming
07-06-2009, 12:51 PM
Hi
I have a grid with any number of rows. Each row has a picturebox drawn next to it.
The pictureboxes have context menu's assigned to them (5 menuitems).
Problem is, selecting an item from the contextmenu makes sender the contextmenu, so I don't know which row's picture box was right-clicked.
My code looks like this at the moment.
Declarations:
private ContextMenu[] mnuLamps;
I have a routine which creates the contextmenus's:
mnuLamps = null;
mnuLamps = new ContextMenu[dsSummary.Tables[0].Rows.Count];
for (int i = 0; i < dsSummary.Tables[0].Rows.Count; i++)
{
mnuLamps = new ContextMenu();
mnuLamps[i].MenuItems.Add(new MenuItem());
mnuLamps[i].MenuItems[0].Text = "Receive";
mnuLamps[i].MenuItems[0].Click += new EventHandler(ReceiveSelected);
...
mnuLamps[i].MenuItems.Add(new MenuItem());
mnuLamps[i].MenuItems[4].Text = "Retract";
mnuLamps[i].MenuItems[4].Click += new EventHandler(RetractSelected);
}
When the pictureboxes are added to the form I have:
for (int i = 0; i < dsSummary.Tables[0].Rows.Count; i++)
{
...
picBox[i].ContextMenu = mnuLamps[i];
...
}
I then have ReceiveSelected, RetractSelected etc as:
private void ReceiveSlecetd(object sender, EventArgs e)
sender is of course menuitem, so I don't know which row it was.
I have thought of using
private void ReceiveSelected(object sender, EventArgs e, int TheRow)
and
mnuLamps[i].MenuItems[0].Click += new EventHandler(ReceiveSelected(mnuLamps[i], [I]EventArgs, );
so that I have access to the row, but I am having trouble doing the [I]EventArgs and I am not sure I can use this code fiddling.
Thanks,
Nigel
I have a grid with any number of rows. Each row has a picturebox drawn next to it.
The pictureboxes have context menu's assigned to them (5 menuitems).
Problem is, selecting an item from the contextmenu makes sender the contextmenu, so I don't know which row's picture box was right-clicked.
My code looks like this at the moment.
Declarations:
private ContextMenu[] mnuLamps;
I have a routine which creates the contextmenus's:
mnuLamps = null;
mnuLamps = new ContextMenu[dsSummary.Tables[0].Rows.Count];
for (int i = 0; i < dsSummary.Tables[0].Rows.Count; i++)
{
mnuLamps = new ContextMenu();
mnuLamps[i].MenuItems.Add(new MenuItem());
mnuLamps[i].MenuItems[0].Text = "Receive";
mnuLamps[i].MenuItems[0].Click += new EventHandler(ReceiveSelected);
...
mnuLamps[i].MenuItems.Add(new MenuItem());
mnuLamps[i].MenuItems[4].Text = "Retract";
mnuLamps[i].MenuItems[4].Click += new EventHandler(RetractSelected);
}
When the pictureboxes are added to the form I have:
for (int i = 0; i < dsSummary.Tables[0].Rows.Count; i++)
{
...
picBox[i].ContextMenu = mnuLamps[i];
...
}
I then have ReceiveSelected, RetractSelected etc as:
private void ReceiveSlecetd(object sender, EventArgs e)
sender is of course menuitem, so I don't know which row it was.
I have thought of using
private void ReceiveSelected(object sender, EventArgs e, int TheRow)
and
mnuLamps[i].MenuItems[0].Click += new EventHandler(ReceiveSelected(mnuLamps[i], [I]EventArgs, );
so that I have access to the row, but I am having trouble doing the [I]EventArgs and I am not sure I can use this code fiddling.
Thanks,
Nigel