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

how to get all the sub menu items of a selected menu item till the irrespective of level?

2 Answers 549 Views
Menu
This is a migrated thread and some comments may be shown as answers.
kk luwang
Top achievements
Rank 1
kk luwang asked on 29 Apr 2010, 03:48 PM
Hi,

I've a requirement to get all the submenu items of a selected menu item till the deepest level whichever is available for that selected menu items. I mean is there any way to get all child sub-menu items and the grandchildren sub-menu items and so on for the selected menu item or is there any way to know the maximum/deepest level of a selected menuitem. As far as i've come across we can only go down the immediate next level of selected menu item. My requirement is to get and store DataFieldID of the selected menu item and all its available child menu items irrespective of the levels it has. Could you please provide me some sample code on this?

Regards,
kk

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 30 Apr 2010, 12:33 PM
Hello,

I used a recursive function to get all the subitems of the clicked menuitem. I used a Dictionary structure in order to save the menuitems which stores the text and index of the sub menuitems.

C#:
 
    Dictionary<stringint> d = new Dictionary<stringint>(); 
    protected void RadMenu1_ItemClick(object sender, RadMenuEventArgs e) 
    { 
        RadMenuItem item = (RadMenuItem)e.Item; 
        getItems(item); 
    } 
    public void getItems(RadMenuItem parentItem) 
    { 
        foreach(RadMenuItem item in  parentItem.Items) 
        { 
            d.Add(item.Text, item.Index); 
            if (item.Items.Count > 0) 
            { 
                getItems(item); 
            } 
        } 
    } 


Regards,
Princy.
0
Veronica
Telerik team
answered on 05 May 2010, 01:59 PM
Hi luwang,

At this moment there is no function to get directly all the child Items for a particular RadMenuItem.

That's why Princy is right! The solution is to use a recursive function. I created a sample project to show you how to do this. It is similar to the code of Princy but I use a List instead of a Dictionary. You may use the solution which you like most.

Find the project in the attached .zip file.

Hope this helps.

Kind regards,
Veronica Milcheva
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
n/a
Top achievements
Rank 1
commented on 28 Sep 2022, 02:39 PM

Hi Princy / Veronica,

How can we use the solution suggested by Princy in Telerik test studio Coded step wherein I don't have access to the UI components code?

I am automating the WPF Desktop application and for verification purpose I need submenu list of selected Menu item.

Can you please help me for the same?

Thanks in advance.

Best regards,

Kanchan

Elena
Telerik team
commented on 30 Sep 2022, 03:19 PM

Hi Kanchan, 

I noticed you have submitted a support thread about this topic and will be happy to continue the discussion in it. We will need to sort out further details for the scenario you need to cover and we can use the private support ticket.

Thanks for your cooperation.

Regards,
Elena

Tags
Menu
Asked by
kk luwang
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Veronica
Telerik team
Share this question
or