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

Get the Entity object associated with a clicked RadMenu item

6 Answers 28 Views
Menu
This is a migrated thread and some comments may be shown as answers.
jay
Top achievements
Rank 1
jay asked on 09 Nov 2011, 08:16 PM

I have a RadMenu that gets its items from a database. Below is the code that correctly populates the items.
What i need is to be able to extract the Report object of type lu_Reports in the Menu ItemClick Event (part of which is also shown below). I can get the name of the report but i need to have the SelectedReport object which i have bound to another control on the page.

 

private void LoadMenuItems(ObservableCollection<lu_Reports> myRptList)
        {
            RadMenuItem parentItem;
            RadMenuItem childItem;
                                     
            try
            {
                if (myRptList != null)
                {
                    foreach (var lu_Modules in _viewModel.ModulesList)
                    {
                        parentItem = new RadMenuItem() { Header = lu_Modules.ModuleName };
                        rptMenu.Items.Add(parentItem);
 
                        foreach (var obj in myRptList.Where(e=> e.ModuleID==lu_Modules.ModuleID))
                        {
                            childItem = new RadMenuItem() { Header = obj.ReportDescription, Name = obj.ReportName };
                            parentItem.Items.Add(childItem);
                        }
                    }
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 
 
private void radMenu_ItemClick(object sender, Telerik.Windows.RadRoutedEventArgs e)
        {
            RadMenuItem item = e.OriginalSource as RadMenuItem;
            if (item != null)
            {
}
}

 

 

6 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 14 Nov 2011, 02:28 PM
Hello Jay,

You can create a class which inherits RadMenuItem and also has additional property that holds the corresponding Report:

public class ExtendedMenuItem : RadMenuItem
{
    public lu_Reports Report { set; get; }
}

then you can add ExtendedMenuItem as items of the menu - the Report can be easily accessed in the ItemClick event handler:

private void rptMenu_ItemClick(object sender, Telerik.Windows.RadRoutedEventArgs e)
{
    var report = (e.OriginalSource as ExtendedMenuItem).Report;
}

Hope this helps.

Greetings,
Yana
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
jay
Top achievements
Rank 1
answered on 14 Nov 2011, 03:00 PM

Thanks, Yana.

I am however getting a nullexception error in the Item_Click event. How do i use an instance of the new class in this event?

 

Jay

 

 

 

ExtendedMenuItem rpt = new ExtendedMenuItem();

 

0
Yana
Telerik team
answered on 15 Nov 2011, 12:24 PM
Hi Jay,

I've attached a simple example to demonstrate the approach. Please download it and give it a try.

Regards,
Yana
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
jay
Top achievements
Rank 1
answered on 15 Nov 2011, 03:09 PM
Hi Yana,

I can't see your attachment.

Thanks
Jay
0
Accepted
Yana
Telerik team
answered on 15 Nov 2011, 03:27 PM
Hi Jay,

I'm sorry. Here is the attachment.

Kind regards,
Yana
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
jay
Top achievements
Rank 1
answered on 15 Nov 2011, 04:41 PM
Thanks, Yana !
That worked.

Jay
Tags
Menu
Asked by
jay
Top achievements
Rank 1
Answers by
Yana
Telerik team
jay
Top achievements
Rank 1
Share this question
or