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

RadDropDown Menu - get selected item?

2 Answers 165 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Richard Thurgood
Top achievements
Rank 1
Richard Thurgood asked on 19 Jul 2008, 03:12 PM
Doing a winform app and I've created the dropdownmenu dynamcically as shown below. Now, I can't figure out how to determine which menu item gets selected so I can execute the proper function. Can you assist?

private void radTreeView1_MouseDown(object sender, MouseEventArgs e)
{
  if (e.Button == MouseButtons.Right)
  {
    RadDropDownMenu radMenu = this.DropDownMenu;               

    RadMenuItem radMenuItem = new RadMenuItem();
    radMenuItem.Text = "Open";
    radMenu.Items.Add(radMenuItem);

    radMenuItem = new RadMenuItem();
    radMenuItem.Text = "Save";
    radMenu.Items.Add(radMenuItem);

    radMenuItem = new RadMenuItem();
    radMenuItem.Text = "Print";
    radMenu.Items.Add(radMenuItem);

    radMenu.Show(radTreeView1, e.Location);
  }  
}

2 Answers, 1 is accepted

Sort by
0
Richard Thurgood
Top achievements
Rank 1
answered on 19 Jul 2008, 09:55 PM
Ah ha!  Can't believe I didn't think of this right off.  Adding an event handler does the trick. Here's the code:

private void radTreeView1_MouseDown(object sender, MouseEventArgs e)
{
  if (e.Button == MouseButtons.Right)
  {
    // this.DropDownMenu.Items.Clear();
    RadDropDownMenu radMenu = new RadDropDownMenu();

    RadMenuItem radMenuItem = new RadMenuItem();
    radMenuItem.Text = "Open Notation";
    radMenu.Items.Add(radMenuItem);
    radMenuItem.Click += new EventHandler(RadMenuItem_Click);

    radMenuItem = new RadMenuItem();
    radMenuItem.Text = "Print Notation";
    radMenu.Items.Add(radMenuItem);
    radMenuItem.Click += new EventHandler(RadMenuItem_Click);

    radMenuItem = new RadMenuItem();
    radMenuItem.Text = "Show Details";
    radMenu.Items.Add(radMenuItem);
    radMenuItem.Click += new EventHandler(RadMenuItem_Click);

    radMenu.Show(radTreeView1, e.Location);
  }

}

private void RadMenuItem_Click(object sender, EventArgs e)
{
  RadMenuItem item = sender as RadMenuItem;
  if (item != null)
  {
    MessageBox.Show(item.Text);
  }
}

0
Jack
Telerik team
answered on 21 Jul 2008, 12:56 PM
Hello Richard,

I am glad to hear you have found a solution to this issue yourself. Do not hesitate to contact us if you need any further assistance!

All the best,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Menu
Asked by
Richard Thurgood
Top achievements
Rank 1
Answers by
Richard Thurgood
Top achievements
Rank 1
Jack
Telerik team
Share this question
or