
Surely there's got to be an easy way to do this.
1 Answer, 1 is accepted
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:
ActiveBrowser.NavigateTo(
"http://demos.telerik.com/aspnet-ajax/combobox/examples/default/defaultcs.aspx"
);
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
Test Studio Trainings
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?
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
Test Studio Trainings
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?
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
Test Studio Trainings
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.
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
Test Studio Trainings
thanks the ClearSelection() worked perfectly