This is a migrated thread and some comments may be shown as answers.

RadDropDownList : Prevent popup close on certain value

1 Answer 286 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
OD
Top achievements
Rank 1
OD asked on 05 Mar 2019, 10:39 AM

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 ;)

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 06 Mar 2019, 12:05 PM
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.
Tags
DropDownList
Asked by
OD
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or