How do I clear the selection of a RadComboBox?

8 posts, 0 answers
  1. brian sullivan
    brian sullivan avatar
    5 posts
    Member since:
    Nov 2007

    Posted 13 Aug 2012 Link to this post

    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.
  2. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 14 Aug 2012 Link to this post

    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
  3. brian sullivan
    brian sullivan avatar
    5 posts
    Member since:
    Nov 2007

    Posted 14 Aug 2012 Link to this post

    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?
  4. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 17 Aug 2012 Link to this post

    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
  5. Wayne
    Wayne avatar
    10 posts
    Member since:
    Feb 2015

    Posted 20 Jun Link to this post

    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?

  6. Elena Tsvetkova
    Admin
    Elena Tsvetkova avatar
    253 posts

    Posted 22 Jun Link to this post

    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
     
  7. Wayne
    Wayne avatar
    10 posts
    Member since:
    Feb 2015

    Posted 22 Jun in reply to Elena Tsvetkova Link to this post

    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.

     

  8. Elena Tsvetkova
    Admin
    Elena Tsvetkova avatar
    253 posts

    Posted 27 Jun Link to this post

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