This is a migrated thread and some comments may be shown as answers.
Context Menu for RadDropDownList
3 Answers 30 Views
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 2
Veteran
Mark asked on 18 Apr 2019, 04:52 PM

Let me tell you what I need first. I need the ability for the users to Un-Select an item in a DropDownList where the DropDownStyle = RadDropDownStyle.DropDownList.  Programmatically, this is pretty easy, I can just do this in code SelectedIndex = -1. Now, that I know I can do this to un-select an item in the dropdownlist, next, I need to give the users the ability to also do this.  My thought was to create a right click context menu that if there was a selected item, to give the user a prompt to clear the selection.  I can't seem to get this to work.  If there is a simpler way to do this, I would like an example.  These dropdown lists are used for reporting, it would suck to have to tell the user to exit the form and reload it just to remove un-select an item in a dropdownlist.

Any help and/or ideas would be gratefully appreciated.

 

Thanks

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 19 Apr 2019, 06:37 AM
Hi Mark,

This is indeed a bit tricky because you need to cancel the popup opening if the right mouse button is used. Here is a complete example of this:
RadContextMenu contenxtMenu = new RadContextMenu();
public RadForm1()
{
    InitializeComponent();
    radDropDownList1.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDownList;
 
    for (int i = 0; i < 10; i++)
    {
        radDropDownList1.Items.Add("Item " +i);
    }
 
    
    RadMenuItem clearItem = new RadMenuItem("Clear Value");
    clearItem.Click += ClearItem_Click;
    this.contenxtMenu.Items.Add(clearItem);
 
    radDropDownList1.MouseDown += RadDropDownList1_MouseDown;
    radDropDownList1.PopupOpening += RadDropDownList1_PopupOpening;
}
bool cancelPopup = false;
private void RadDropDownList1_PopupOpening(object sender, CancelEventArgs e)
{
    e.Cancel = cancelPopup;
    cancelPopup = false;
}
 
private void RadDropDownList1_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Right)
    {
        this.contenxtMenu.Show(radDropDownList1, e.Location);
        cancelPopup = true;
    }
}
 
private void ClearItem_Click(object sender, EventArgs e)
{
    radDropDownList1.SelectedIndex = -1;
}

I hope this helps. Should you have any other questions do not hesitate to ask.
 
Regards,
Dimitar
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Mark
Top achievements
Rank 2
Veteran
answered on 19 Apr 2019, 11:24 AM

I was so close...I just didn't catch on to the PopupOpening event.  I was looking for it, just didn't see it.  

 

Thanks

0
Dimitar
Telerik team
answered on 19 Apr 2019, 12:17 PM
Hello Mark,

I am glad that this works now. Do not hesitate to contact us if you have other questions.
 
Regards,
Dimitar
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Asked by
Mark
Top achievements
Rank 2
Veteran
Answers by
Dimitar
Telerik team
Mark
Top achievements
Rank 2
Veteran
Share this question
or