ContextMenu

P

PawelR

Hello group,

I have problem with contextMenu. On my Form I have for dataGrid (with TabA,
TabB, TabC, TabD) in context menu I chanege displayed records (show all,
show record where col is True etc.). For all dataGrid I have the same
command.
Now I use seaparate contextMenu for all dataGrids. How get object
(dataGrid.DataSource) how started context menu?
If it is possible I use only one contextMenu for all datagrids.

Thx
Pawel
 
M

Mohamoss

Hi Pawel
Sure you can use one context menu for all the four datagrid , then inside
the event handler of what ever event in a menu item . you detect the source
control ( the one that the menu item event has been invoked from ) this way
you can get the control that invoaked the event at that time and act
accordingly. Imagine for example that you are using the menu with two
button control , the first of them has the name one the other has the name
two , you can have something like that
private void menuItem1_Click(object sender, System.EventArgs e)
{
System.Windows.Forms.Button temp =( Button)
this.contextMenu1.SourceControl;
if (temp.Name == "one")
{
MessageBox.Show("button one was clicked");
}
else {
MessageBox.Show("button TWO was clicked");
}
}

Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top