How do I clear the selection of a RadComboBox?

1 Answer 3622 Views
General Discussions
brian sullivan
Top achievements
Rank 1
brian sullivan asked on 13 Aug 2012, 04:49 PM
I've got a RadComboBox that I'm trying to clear the selection on. There doesn't seem to be a method on the combo box itself to do it, and I can't find a way to get ahold of the "Clear Selection" button I've enabled on the combo box. The SelectedIndex property isn't nullable, so I can't do that, and it doesn't have a "SelectedValue" property.

Surely there's got to be an easy way to do this.

1 Answer, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 14 Aug 2012, 01:19 PM
Hi Brian Sullivan,

As you can see in this article, resetting the combobox selection depends on the AllowCustomText property - if it is set to True then you can clear the combobox using its ClearSelection() method or setting its Text property to an empty string.

Here's a sample code against this RadComboBox demo site:
 
RadComboBox cb = ActiveBrowser.Find.ById<RadComboBox>("RadComboBoxProduct");
 
//Open ComboBox dropdown
cb.ShowDropDown();
cb.Refresh();
 
//Select an Item
cb.SelectItemByText("Chai");
 
//Clear the ComboBox selection
cb.ClearSelection();


Kind regards,
Plamen
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
brian sullivan
Top achievements
Rank 1
commented on 14 Aug 2012, 01:53 PM

Plamen,

Thanks for the answer. I forgot to mention that I'm using the RadComboBox in WPF, not ASP.NET. The WPF RadComboBox object does not have a ClearSelection method. Could you tell me how to do this using the WPF control?
Plamen
Telerik team
commented on 17 Aug 2012, 12:46 PM

Hello Brian Sullivan,

Thanks for the clarification. You are right, there is no ClearSelection method for the WPF RadComboBox. Instead you need to implement and use the clear selection button as seen in this article.

Once you have the clear selection button implemented you can use it with code like this:
RadComboBox cb = ActiveApplication.MainWindow.Find.ByName<RadComboBox>("radComboBox1");
 
//Open drop-down
cb.ToggleDropDown();
 
//Click on the clear selection button
cb.Find.ByType<RadButton>().User.Click();


All the best,
Plamen
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Wayne
Top achievements
Rank 1
commented on 20 Jun 2016, 10:33 AM

Is there any updated answer on the way to do this in WPF?

Surely this should be simple to do, but I'm wasting time trying to figure it out. The answer above doesn't make much sense to me since I see no ToggleDropDown() method on RadComboBox. Plus I find the answer rather bizarre in that it seems to imply you need to enable a visual element that you may not even want, just be to be able to clear the selection?

Elena
Telerik team
commented on 22 Jun 2016, 02:34 PM

Hello Wayne,

Thank you for contacting Telerik Support Team. 

Since the thread you found is since almost four years I would like to ask you to share further details on your exact issue. If you are able to provide some screenshots along with the details it will be quite helpful. 

Looking forward to hearing from you. 

Regards,
Elena Tsvetkova
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
Wayne
Top achievements
Rank 1
commented on 22 Jun 2016, 03:19 PM

Hi Elena,

I have been working on a Ribbon Search feature (that is still a work in progress, but not far off completion) and was trying to find a way to clear the text that appears in the RadComboBox after a selection is made by the user, to revert to the default "EmptyText" property. That is, I don't want the user selection to appear in the combo text box; that is purely for the user's search term. When the user selects an item I wish to close the drop down, take some action, and revert to the initial "EmptyText" state.

I figured out how to clear the selection; I first have to clear the items in the combo list. (I am working directly with the Items property (ItemsCollection) since binding has no advantage in this instance; each search term a user types, regenerates the entire drop down list content). Next I have to set SelectedItem to null. Finally, the trickiest part to figure out, and somewhat of a hack, to get the RadComboBox to revert to the EmptyText ("Search Ribbon (F3)") I have to move focus to another control in the Ribbon (UpdateTextOnLostFocus is also set to true, but it doesn't seem to matter if it is set to false). I wonder why there cannot be a method to clear the selection and immediately revert to "EmptyText", thus saving all the previously mentioned steps, but I understand from reviewing the source code that the control is pretty complicated and may not be designed with my use case in mind.

Anyway, I have found a way to do what I want, just a matter of minutes ago, so it will be OK as-is.

Regards,

Wayne.

 

Elena
Telerik team
commented on 27 Jun 2016, 08:13 AM

Hi Wayne,

Thanks one more time for your understanding. As of the feedback you added I assume that the control you are trying to automate in a particular way is not actually designed that way. I am glad you were able to figure out how to solve your query. 

I would like to kindly ask you whenever you would like to ask for further support to submit new issue for better visibility from our side. Even if there is an old theme in relation to your question Test Studio is a continuously developing tool and there are new functionalities and features with every next release. 

Thanks a lot for your cooperation and do not hesitate to contact Telerik Support Team case you need any further assistance. 

Wish you enjoy your day! 

Regards,
Elena Tsvetkova
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
Tunde
Top achievements
Rank 1
commented on 25 Jun 2019, 01:45 PM

thanks the ClearSelection() worked perfectly

Tags
General Discussions
Asked by
brian sullivan
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Share this question
or