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

radDropDownButtonElement Click Event

5 Answers 355 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
rahul
Top achievements
Rank 1
rahul asked on 27 Sep 2010, 07:14 AM

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

5 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 27 Sep 2010, 11:12 AM
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
0
Peter
Telerik team
answered on 30 Sep 2010, 03:57 PM
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
0
Shabeer
Top achievements
Rank 1
answered on 22 Jan 2013, 09:19 AM
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.

0
Peter
Telerik team
answered on 23 Jan 2013, 08:43 AM
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.
0
Shabeer
Top achievements
Rank 1
answered on 23 Jan 2013, 11:02 AM
Hi


Its working perfect.



Thank you

Tags
DropDownList
Asked by
rahul
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Peter
Telerik team
Shabeer
Top achievements
Rank 1
Share this question
or