RadDropDownList : Prevent popup close on certain value

2 posts, 0 answers
  1. QuizzBox
    QuizzBox avatar
    92 posts
    Member since:
    Jan 2011

    Posted 05 Mar Link to this post

    Hey, 

    Is there a way to prevent the popup closing when i select a certain value ?

    On PopupClosing event, with args=true, i can cancel event but the selectValue return the old value, not the new selected.

    Thanks in advance ;)

  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3327 posts

    Posted 06 Mar Link to this post

    Hello, Jean-Marc,    
     
    Indeed, the PopupClosing event is the appropriate way to prevent closing the popup in certain conditions. Indeed, the new value is committed when the popup is closed. 

    However, I can suggest you to handle the Popup.MouseDown event and detect which item was clicked and use this information in the PopupClosing event. Please refer to the following code snippet:
     
    bool cancel = false;
     
    public RadForm1()
    {
        InitializeComponent();
     
        this.radDropDownList1.PopupClosing += radDropDownList1_PopupClosing;
        this.radDropDownList1.PopupOpened += radDropDownList1_PopupOpened;
        this.radDropDownList1.Popup.MouseDown += Popup_MouseDown;
    }
     
    private void Popup_MouseDown(object sender, MouseEventArgs e)
    {
        RadListVisualItem visualItem = this.radDropDownList1.Popup.ElementTree.GetElementAtPoint(e.Location) as RadListVisualItem;
        if (visualItem != null && visualItem.Data.Text.Contains("4"))
        {
            cancel = true;
        }
        else
        {
            cancel = false;
        }
    }
     
    private void radDropDownList1_PopupOpened(object sender, EventArgs e)
    {
        cancel = false;
    }
     
    private void radDropDownList1_PopupClosing(object sender, Telerik.WinControls.UI.RadPopupClosingEventArgs args)
    {
        args.Cancel = cancel;
    }

    I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

    Regards,
    Dess | Tech Support Engineer, Sr.
    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