The heart of RadDropDownButton is the Items collection. This collection defines the menu items that appear when the RadDropDownButton is clicked. To get started, drag a RadDropDownButton on the surface of your form from the Toolbox. There are two ways to add items to your new button.
Adding Items at Design Time
To add menu items at Design Time, click on the Items property(the ellipsis button) to launch the RadElement Collection Editor. Click the arrow next to the Add button to add items to the menu. You can add a variety of items to the collection.
Once you have added a RadMenuItem to the collection, it will appear in the list on the left side of the dialog. Click the RadMenuItem to edit its properties in the corresponding property grid on the right of the dialog.
In the property grid you will find many of the standard control properties, including Text, to control the display text of the item and ToolTipText that displays when the mouse hovers over an item. Each RadMenuItem you add also contains an Items collection of its own, allowing you to create menu hierarchies in the RadDropDownButton. You can also do the following with each item:
-
Associate an image to an item using the Image property or associate a standard ImageList component to the RadDropDownButton and use the ImageIndex or ImageKey properties for the item.
- PopupDirection determines the direction in which the sub items of a RadMenuItem will be displayed and can be Left, Right, Up or Down.
-
To display sub items in two columns set HasTwoColumns to true and add items to the RightColumnItems collection.
-
Use CheckOnClick to toggle a check mark next to a RadMenuItem. This property is appropriate to use when the item doesn't contain sub items.
Adding Items at Run Time in Code
You can also add RadDropDownButton items in code at Run Time. The following example code illustrates how to programmatically add a RadMenuItem to your button.
Copy[C#] Adding RadDropDownButton items
void Form1_Load(object sender, EventArgs e)
{
RadMenuItem myRadMenuItem = new RadMenuItem();
myRadMenuItem.Text = "My New Item";
radDropDownButton1.Items.Add(myRadMenuItem);
myRadMenuItem.Click += new EventHandler(myRadMenuItem_Click);
}
void myRadMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show((sender as Telerik.WinControls.UI.RadMenuItem).Text +
" was clicked.");
}
Copy[VB.NET] Adding RadDropDownButton items
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myRadMenuItem As New RadMenuItem()
myRadMenuItem.Text = "My New Item"
radDropDownButton1.Items.Add(myRadMenuItem)
AddHandler myRadMenuItem.Click, AddressOf myRadMenuItem_Click
End Sub
Sub myRadMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
MessageBox.Show((TryCast(sender, RadMenuItem)).Text + " was clicked.")
End SubSimilarly, you can create item hierarchies in code by adding new RadMenuItem objects to the Items collection of your existing RadMenuItem.
Copy[C#] Adding sub items
using Telerik.WinControls.UI;
namespace RadDropDownButtonDemo
{
public partial class Form1 : Form
{
private void Form1_Load(object sender, EventArgs e)
{
RadMenuItem mainItem = radDropDownButton1.Items[0] as RadMenuItem;
RadMenuItem mySubMenuItem = new RadMenuItem();
mySubMenuItem.Text = "Submenu Item";
mySubMenuItem.Click += new EventHandler(mySubMenuItem_Click);
mainItem.Items.Add(mySubMenuItem);
}
void mySubMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show((sender as RadMenuItem).Text +
" was clicked.");
}
}
}
Copy[VB.NET] Adding sub items
Imports System.Windows.Forms
Imports Telerik.WinControls.UI
Namespace RadDropDownButtonDemo
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim mainItem As RadMenuItem = TryCast(radDropDownButton1.Items(0), RadMenuItem)
Dim mySubMenuItem As New RadMenuItem()
mySubMenuItem.Text = "Submenu Item"
AddHandler mySubMenuItem.Click, AddressOf mySubMenuItem_Click
mainItem.Items.Add(mySubMenuItem)
End Sub
Sub mySubMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
MessageBox.Show((TryCast(sender, RadMenuItem)).Text + " was clicked.")
End Sub
End Class
End Namespace
Displaying Images with Items
You can display images and text on your menu items.
To add an image to your menu item, click in the Image property of the RadMenuItem, and then click the ellipsis button to launch the Select Resource dialog. From this dialog you can select an image file from a project resource file or from an image resource on your local hard drive.
Using the Click Event
To handle the Click event of individual RadMenuItems on the drop down menu at Design Time, locate the RadMenuItem in the drop down list in the Properties window of the Windows Form designer. Click the events button, then double-click the Click event to generate an event handler. Then fill in your event-handling code.