Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > Menu > Get the Entity object associated with a clicked RadMenu item

Answered Get the Entity object associated with a clicked RadMenu item

Feed from this thread
  • jay avatar

    Posted on Nov 9, 2011 (permalink)

    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)
                {
    }
    }

     

     

    Reply

  • Yana Yana admin's avatar

    Posted on Nov 14, 2011 (permalink)

    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 >>

    Reply

  • jay avatar

    Posted on Nov 14, 2011 (permalink)

    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();

     

    Reply

  • Yana Yana admin's avatar

    Posted on Nov 15, 2011 (permalink)

    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 >>

    Reply

  • jay avatar

    Posted on Nov 15, 2011 (permalink)

    Hi Yana,

    I can't see your attachment.

    Thanks
    Jay

    Reply

  • Answer Yana Yana admin's avatar

    Posted on Nov 15, 2011 (permalink)

    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 >>

    Attached files

    Reply

  • jay avatar

    Posted on Nov 15, 2011 (permalink)

    Thanks, Yana !
    That worked.

    Jay

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > Menu > Get the Entity object associated with a clicked RadMenu item
Related resources for "Get the Entity object associated with a clicked RadMenu item"

Silverlight Menu Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]