Hi Najoua,
If the drop-down list is flat (with no hierarchy) the easiest way to do this is to use RadComboBox. If you want to have hierarchical menus in the drop-down you will have to use RadDropDownButton or RadSplitButton. In both cases you will need to write some code.
Here is given example for RadDropDownButton.
First subscribe for
Load and
FormClose events of the Form and fill them like this:
private void Form1_Load(object sender, EventArgs e) |
{ |
RadDropDownButtonElement buttonElement = (RadDropDownButtonElement)this.radDropDownButton1.RootElement.Children[0]; |
SubscribeMenuItems(buttonElement.DropDownMenu.Items); |
} |
|
private void Form1_FormClosed(object sender, FormClosedEventArgs e) |
{ |
RadDropDownButtonElement buttonElement = (RadDropDownButtonElement)this.radDropDownButton1.RootElement.Children[0]; |
UnsubscribeMenuItems(buttonElement.DropDownMenu.Items); |
} |
Then add these private methods to the body of your Form class:
private void SubscribeMenuItems(RadItemCollection menuItems) |
{ |
for (int i = 0; i < menuItems.Count; i++) |
{ |
RadMenuItem subMenuItem = menuItems[i] as RadMenuItem; |
if (subMenuItem != null) |
{ |
if (subMenuItem.Items.Count == 0) |
subMenuItem.Click += new EventHandler(DropDownMenuItem_Click); |
else |
SubscribeMenuItems(subMenuItem.Items); |
} |
} |
} |
|
private void UnsubscribeMenuItems(RadItemCollection menuItems) |
{ |
for (int i = 0; i < menuItems.Count; i++) |
{ |
RadMenuItem subMenuItem = menuItems[i] as RadMenuItem; |
if (subMenuItem != null) |
{ |
if (subMenuItem.Items.Count == 0) |
subMenuItem.Click -= new EventHandler(DropDownMenuItem_Click); |
else |
UnsubscribeMenuItems(subMenuItem.Items); |
} |
} |
} |
|
private void DropDownMenuItem_Click(object sender, EventArgs e) |
{ |
RadMenuItem clickedMenuItem = (RadMenuItem)sender; |
this.radDropDownButton1.Text = clickedMenuItem.Text; |
} |
Hope this was helpful.
Sincerely yours,
Angel
the Telerik team