RadDropDown Menu - get selected item?

3 posts, 0 answers
  1. Richard Thurgood
    Richard Thurgood avatar
    26 posts
    Member since:
    Nov 2007

    Posted 19 Jul 2008 Link to this post

    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. Richard Thurgood
    Richard Thurgood avatar
    26 posts
    Member since:
    Nov 2007

    Posted 19 Jul 2008 Link to this post

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

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 21 Jul 2008 Link to this post

    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
Back to Top