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

contextmenu names

3 Answers 55 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Andrea Della Santa
Top achievements
Rank 1
Andrea Della Santa asked on 03 Nov 2008, 02:33 PM
Hi,

In GridView, contextmenu are generated on the fly.

In ContextMenuOpening , I can access the items with index.

e.ContextMenu.Items[3]

But how access it by name ? For example, what's the default name for items[0] please ?



3 Answers, 1 is accepted

Sort by
0
John
Top achievements
Rank 1
answered on 03 Nov 2008, 09:25 PM
Hi Andrea,
   Well, you will not be able to reference the menu item [0] at design time because it doesn't exist until runtime.  If you are trying to differentiate the menu items you can view the Text property of the item.  

if (string.Compare(e.ContextMenu.Items[0].Text, "Copy"true) == 0)  
{  
     //The copy menu  

I hope this helps with your issue.

John
0
Andrea Della Santa
Top achievements
Rank 1
answered on 04 Nov 2008, 11:59 AM
Thanks but my problem is I need to remove any of item in contextopening.
If I refer to index, it's ok until I change options for gridview (example, if I allow or not to delete row, the menu struture differ and my code isn't valid.

I can't refer to text because the texte items is localized. So the text isn't the same.

0
Nick
Telerik team
answered on 07 Nov 2008, 02:01 PM
John's suggestion is very good. You can still use the localized strings to check the menu content items.

I could also think of other alternatives like using the e.ContextMenu.Items.Count property or some boolean flags keeping track of the changes of the menu items structure (e.g. Copy/Paste change).

private void radGridView1_ContextMenuOpening(object sender, Telerik.WinControls.UI.ContextMenuOpeningEventArgs e) 
    if (e.ContextMenu.Items.Count == SomeNumber) {  
          
    } 


Do not hesitate to write me back if you have further questions.

Kind regards,
Nick
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
Andrea Della Santa
Top achievements
Rank 1
Answers by
John
Top achievements
Rank 1
Andrea Della Santa
Top achievements
Rank 1
Nick
Telerik team
Share this question
or