Clear Selected Items

4 posts, 0 answers
  1. Wayne Williams
    Wayne Williams avatar
    38 posts
    Member since:
    Jul 2019

    Posted 22 Aug Link to this post

    Have a bit of an odd situation. I have two AutoCompleteBoxes. Both are bound are in a near-identical manner, the only difference being that the 2nd one is bound to a filtered view of the data bound to the 1st box:

    Box 1: ItemsSource="{Binding SearchRecords}" DisplayMemberPath="SearchValue" SelectedItem="{Binding SearchBox1SelectedItem, Mode=TwoWay}"

    Box 2: ItemsSource="{Binding SearchRecords2View}" DisplayMemberPath="SearchValue" SelectedItem="{Binding SearchBox2SelectedItem, Mode=TwoWay}"

    After the second selection is made, I take some query actions, which work correctly. I then attempt to blank both boxes to clear the slate for the next user action:

    SearchBox1SelectedItem = null;
    SearchBox2SelectedItem = null;

    Both property setters handle this in the same way:

    if (_searchBox1SelectedItem != value)
                    {
                        _searchBox1SelectedItem = value;
                        RaisePropertyChanged();
                    }

     if (_searchBox2SelectedItem != value)
                    {
                        _searchBox2SelectedItem = value;
                        RaisePropertyChanged();
                    }

    The effect on the SearchBox1 is as expected, i.e. the box clears itself, as shown in its properties as per AutoCompleteBox1.jpg, attached.

    But this does not happen as expected for SearchBox2. Instead, it seems to have made an aborted attempt to clear itself, as per AutoCompleteBox2.jpg. Note how the SelectedItem value for SearchBox2 has been nullified, as intended, but it retains 1 record in its SelectedItems list, and also note how its SearchText, which is set to "Bil", should in fact be "Billy Joel", which is what still appears in the Search Box.

    Any ideas?

     

  2. Vladimir Stoyanov
    Admin
    Vladimir Stoyanov avatar
    495 posts

    Posted 27 Aug Link to this post

    Hello Wayne,


    Thank you for the provided pictures and sample code.

    In order to clear the selection, you can set the SelectedItems property to null.  Here is what I have in mind:

    this.AutoCompleteBox.SelectedItems = null;

    Can you give this approach a try and let me know how it goes?

    I am looking forward to your reply.

    Regards,
    Vladimir Stoyanov
    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.
  3. Wayne Williams
    Wayne Williams avatar
    38 posts
    Member since:
    Jul 2019

    Posted 11 Sep in reply to Vladimir Stoyanov Link to this post

    Sorry for the delayed response. As a newbie, I was trying to handle all this in the view model in keeping with MVVM, but then your comment made me rethink this, as the manipulation of controls (focus, visibility, interplay between selection boxes) is really a view issue (i.e. after the view model has been properly handled), so I switched approaches, including your suggestion, and everything works as intended.
  4. Vladimir Stoyanov
    Admin
    Vladimir Stoyanov avatar
    495 posts

    Posted 13 Sep Link to this post

    Hello Wayne,

    I am glad to hear that my suggestion helped. 

    Don't hesitate to contact us again, if you have any other questions or concerns.

    Regards,
    Vladimir Stoyanov
    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