This is a migrated thread and some comments may be shown as answers.

Get Parent Control of the Context Menu

3 Answers 149 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sasmita
Top achievements
Rank 1
Sasmita asked on 08 Jul 2008, 05:58 PM
Hi,

I have a page that contains two data grid view controls. Both the Grid View Controls are sharing a common Context Menu. When i Select any Context menu item(let's Say Copy) i need to know which Data Grid View Control opened up the Context menu. So when the MenuItem Click event is fired i need to know the event is fired on which Grid.....

Could any body please help me out..

Any kind of help is appreciated.

Sasmita

3 Answers, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 09 Jul 2008, 11:43 AM
Hi Sasmita,

Thank you for writing.

You didn't give us much details about your scenario and from what I see, I can suggest you use ContextMenu.Tag property to store information about the grid that called the context menu.
Consider the code-block below:

private void radGridView1_ContextMenuOpening(object sender, Telerik.WinControls.UI.ContextMenuOpeningEventArgs e)  
{  
    contextMenu.Tag = this.radGridView1;  
    e.ContextMenu = myCustomContextMenu;  
}  
  
private void radGridView2_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)  
{  
    contextMenu.Tag = this.radGridView2;  
    e.ContextMenu = myCustomContextMenu;  
}  
  
//.....  
  
void menuItem1_Click(object sender, EventArgs e)  
{  
    MessageBox.Show(String.Format("\"menuItem1\" was clicked from {0}", ((Control)myCustomContextMenu.Tag).Name));  
}  

I hope this helps. If you have other questions, do not hesitate to contact me again.

Kind regards,
Martin Vasilev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Sasmita
Top achievements
Rank 1
answered on 09 Jul 2008, 10:13 PM
Hi ,

Previous article was helpful. But we encountered one more problem.

When i am attaching a customized context menu in the master grid,  it applies to the entire grid. The code i used is given below. But i want the default to be  retained when user selects the Header or Footer.  Requirement is only when user selects a Row or data in the grid my Customised Custom menu should be shown else the default one should be shown.

private void radGridView2_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)  
{  
    contextMenu.Tag = this.radGridView2;  
    e.ContextMenu = myCustomContextMenu;  
}  

Could anybody please help me out.


Regards,
Sasmita
0
Martin Vasilev
Telerik team
answered on 11 Jul 2008, 02:36 PM
Hi Sasmita,

Thank you for getting back to me.

In the ContextMenuOpening event check whether ContextMenuProvider is different from GridHeaderCellElement:
 
private void radGridView1_ContextMenuOpening(object sender, Telerik.WinControls.UI.ContextMenuOpeningEventArgs e) 
    if(!(e.ContextMenuProvider is GridHeaderCellElement)) 
    { 
        myCustomContextMenu.Tag = this.radGridView1.Name; 
        e.ContextMenu = myCustomContextMenu; 
    } 

If you need additional assistance, do not hesitate to contact me again.

 
Sincerely yours,
Martin Vasilev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
GridView
Asked by
Sasmita
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Sasmita
Top achievements
Rank 1
Share this question
or