Context Menu for RadDropDownList

4 posts, 0 answers
  1. Mark
    Mark avatar
    118 posts
    Member since:
    Oct 2014

    Posted 18 Apr Link to this post

    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

  2. Dimitar
    Admin
    Dimitar avatar
    2789 posts

    Posted 19 Apr Link to this post

    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.
  3. Mark
    Mark avatar
    118 posts
    Member since:
    Oct 2014

    Posted 19 Apr in reply to Dimitar Link to this post

    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

  4. Dimitar
    Admin
    Dimitar avatar
    2789 posts

    Posted 19 Apr Link to this post

    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.
Back to Top