radDropDownButtonElement Click Event

6 posts, 0 answers
  1. rahul
    rahul avatar
    2 posts
    Member since:
    Jun 2010

    Posted 27 Sep 2010 Link to this post

    Hi!


    I have a radDropDownButtonElement in my Window Application I filled the radDropDownButtonElement with  Items (RadMenuItems) at runtime.So if one of these Item is clicked I have to do something. I'm not able to find any click event for this.so suggest me how should I make it?

    Thank you for supporting me!

    Rahul
  2. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 27 Sep 2010 Link to this post

    Hi, 

    Example would be... 

    1: Declare the drop down items that you are putting into your drop down button
    Private WithEvents m_DropDownItem1 As Telerik.WinControls.UI.RadMenuButtonItem

    2: In (for example) Form_Load, add the item
    m_DropDownItem1 = New Telerik.WinControls.UI.RadMenuButtonItem("Click Me")
    Me.RadDropDownButton1.Items.Add(m_DropDownItem1)

    3: Handle the click event for the Drop Down Item
    Private Sub DropDownItem_Clicked(ByVal sender As Object, ByVal e As EventArgs) Handles m_DropDownItem1.Click
        MessageBox.Show(m_DropDownItem1.Text)
    End Sub

    hope that helps
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 30 Sep 2010 Link to this post

    Hi rahul,

    Thanks for the writing.

    As Richard has suggested, you should manually subscribe to Items' Click event:
    Please refer to the code below.
    private void Form1_Load(object sender, System.EventArgs e)
    {
         foreach (RadMenuItem currentItem in this.radDropDownButtonElement1.Items)
         {
              currentItem.Click += currentItem_Click;
         }
    }
     
    void currentItem_Click(object sender, System.EventArgs e)
    {
          RadMenuItem currentItem = sender as RadMenuItem;
          Debug.Assert(currentItem != null, "Sender is not RadMenuItem");
     
          MessageBox.Show("'"+currentItem.Text + "' is clicked");
    }

    Richard, your Telerik points have been updated for the assistance.

    I hope this helps.

    Regards,
    Peter
    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
  5. Shabeer
    Shabeer avatar
    3 posts
    Member since:
    Jan 2013

    Posted 22 Jan 2013 Link to this post

    Hi,

    Greetings from Shabeer..



    i Used the mentioned code for handling the click event, its handling only the first RadMenuItem click event.

    I am using separator item in between and it has multilevel menus also.

  6. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 23 Jan 2013 Link to this post

    Hello Shabeer,

    Thank you for writing.

    In case that you have Separators and Child Items in the Menu Items you should use the follow code:
    private void Form1_Load(object sender, EventArgs e)
    {
        foreach (RadItem currentItem in this.radDropDownButton1.Items)
        {
            RadMenuItem menuItem = currentItem as RadMenuItem;
            if (menuItem != null)
            {
                menuItem.Click += currentItem_Click;
                foreach (RadItem childItem in menuItem.Items)
                {
                    RadMenuItem childMenuItem = childItem as RadMenuItem;
                    if (childMenuItem != null)
                    {
                        childMenuItem.Click += currentItem_Click;
                    }
                }
            }
        }
    }

    I hope this helps. Regards,
    Peter
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
  7. Shabeer
    Shabeer avatar
    3 posts
    Member since:
    Jan 2013

    Posted 23 Jan 2013 Link to this post

    Hi


    Its working perfect.



    Thank you
Back to Top
UI for WinForms is Visual Studio 2017 Ready