Please help ...and thanks in advance!
16 Answers, 1 is accepted
The RadDropDownButton works a differently than a ComboBox where you select an item and the SelectionChanged event fires or you determine which index was selected. The items for the RadDropDownButton are more like menu items where each entry will have it's own click event.
Hope this helps,
John
If you are adding the entry through code it would look something like this.
private void Form1_Load(object sender, EventArgs e) |
{ |
radDropDownButton1.Items.Clear(); |
//create menu item |
var menuItem0 = new Telerik.WinControls.UI.RadMenuItem("Click me", "0"); |
//add event handler |
menuItem0.Click += new EventHandler(menuItem0_Click); |
//add menu option to the RadDropDownButton |
radDropDownButton1.Items.Add(menuItem0); |
} |
void menuItem0_Click(object sender, EventArgs e) |
{ |
//perform logic for the menu item here |
throw new NotImplementedException(); |
} |
You can of course, add these directly in the Visual Studio designer as well.
John
Thanks again
private void Form1_Load(object sender, EventArgs e) |
{ |
LoadMenuOptions(5); |
} |
private void LoadMenuOptions(int numberOfItems) |
{ |
//remove any existing event handler references |
foreach (Telerik.WinControls.UI.RadMenuItem entry in radDropDownButton1.Items) |
{ |
//remove the existing event handler |
entry.Click -= new EventHandler(menuItems_Click); |
} |
radDropDownButton1.Items.Clear(); |
for (int i = 0; i < numberOfItems; i++) |
{ |
//create menu item |
var currentMenuItem = new Telerik.WinControls.UI.RadMenuItem("Click me" + i.ToString(), i); |
//add event handler |
currentMenuItem.Click += new EventHandler(menuItems_Click); |
//add menu option to the RadDropDownButton |
radDropDownButton1.Items.Add(currentMenuItem); |
} |
} |
void menuItems_Click(object sender, EventArgs e) |
{ |
if ((int)((Telerik.WinControls.UI.RadMenuItem)sender).Tag == 0) |
{ |
MessageBox.Show("Perform logic for option 0"); |
} |
else if ((int)((Telerik.WinControls.UI.RadMenuItem)sender).Tag == 2) |
{ |
MessageBox.Show("Perform logic for option 2"); |
} |
else |
{ |
MessageBox.Show("Perform logic for one of the other options"); |
} |
} |
So as you can see I don't have any specific reference to a hard coded entry, the tag does not have to be an integer, I just chose that for my example.
Hope this helps,
John
In order to show the drop down items when the mouse is over the RadDropDownButton, you can subscribe to the
RadDropDownButton.MouseHover event and call the ShowDropDown method:
public
RadForm1()
{
InitializeComponent();
this
.radDropDownButton1.MouseHover+=radDropDownButton1_MouseHover;
}
private
void
radDropDownButton1_MouseHover(
object
sender, EventArgs e)
{
this
.radDropDownButton1.ShowDropDown();
}
I hope this information helps.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
You can find below the modified code snippet how to keep the drop down opened when the mouse is over the popup:
public
RadForm1()
{
InitializeComponent();
this
.radDropDownButton1.MouseHover += radDropDownButton1_MouseHover;
this
.radDropDownButton1.MouseLeave += radDropDownButton1_MouseLeave;
this
.radDropDownButton1.DropDownButtonElement.DropDownMenu.MouseLeave += DropDownMenu_MouseLeave;
}
private
void
DropDownMenu_MouseLeave(
object
sender, EventArgs e)
{
Point pt =
this
.radDropDownButton1.DropDownButtonElement.PointToControl(MousePosition);
if
(!
this
.radDropDownButton1.DropDownButtonElement.Bounds.Contains(pt))
{
this
.radDropDownButton1.HideDropDown();
}
}
private
void
radDropDownButton1_MouseLeave(
object
sender, EventArgs e)
{
Point pt =
this
.radDropDownButton1.DropDownButtonElement.PointToControl(MousePosition);
if
(!
this
.radDropDownButton1.DropDownButtonElement.DropDownMenu.Bounds.Contains(pt))
{
this
.radDropDownButton1.HideDropDown();
}
}
private
void
radDropDownButton1_MouseHover(
object
sender, EventArgs e)
{
this
.radDropDownButton1.ShowDropDown();
}
I hope this information helps.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
hiiii....sometimes i cant access Raddropdownbutton items when mouse is leave....please look at my attached image...when i am trying to open PDC Report on the menu(attached image)...i can't access that menu items...i hope you can understand my problem
here is my code
this.radDropDownButton1.MouseHover += radDropDownButton1_MouseHover;
this.radDropDownButton1.MouseLeave += radDropDownButton1_MouseLeave;
this.radDropDownButton1.DropDownButtonElement.DropDownMenu.MouseLeave += DropDownMenu_MouseLeave;
private void DropDownMenu_MouseLeave(object sender, EventArgs e)
{
Point pt = this.radDropDownButton1.DropDownButtonElement.PointToControl(MousePosition);
if (!this.radDropDownButton1.DropDownButtonElement.Bounds.Contains(pt))
{
this.radDropDownButton1.HideDropDown();
}
}
private void radDropDownButton1_MouseLeave(object sender, EventArgs e)
{
Point pt = this.radDropDownButton1.DropDownButtonElement.PointToControl(MousePosition);
if (!this.radDropDownButton1.DropDownButtonElement.DropDownMenu.Bounds.Contains(pt))
{
this.radDropDownButton1.HideDropDown();
}
}
private void radDropDownButton1_MouseHover(object sender, EventArgs e)
{
this.radDropDownButton1.ShowDropDown();
}
Hello, Ras Ran,
According to the provided sample video, it seems that the drop down gets closed when the mouse leaves the item for which it is shown and the drop down itself doesn't contain focus. Please have a look at the video again and pay attention to the case when the drop down is not closed - the mouse is slightly moved from the item to the drop down. However, in the case when the drop down is not accessible, you move the mouse from the item to the space outside the item and the drop down. That is why it gets closed.Please try to move slightly the mouse from the item directly to the drop down without hovering the space outside them. In this case, you are not expected to get the drop down closed.
I hope this information helps.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).
Thanks for the reply Dess.....its solved anyway....i have one more doubt...how to change Raddropdownbutton RadMenuItem Back color ?? is there any way ??
You can change the color of a RadMenuItem by setting the RadMenuItem.FillPrimitive.BackColor property to the desired color:
foreach (RadMenuItem item in this.radDropDownButton1.Items)
{
item.FillPrimitive .BackColor = Color.Yellow;
}
I believe that you will find this information helpful for achieving your styling requirements.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.