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

Clear Selected Items

3 Answers 54 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
n/a
Top achievements
Rank 1
n/a asked on 23 Aug 2019, 02:08 AM

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?

 

3 Answers, 1 is accepted

Sort by
0
Vladimir Stoyanov
Telerik team
answered on 27 Aug 2019, 12:26 PM

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.
0
n/a
Top achievements
Rank 1
answered on 11 Sep 2019, 10:18 PM
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.
0
Vladimir Stoyanov
Telerik team
answered on 13 Sep 2019, 02:00 PM

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.
Tags
AutoCompleteBox
Asked by
n/a
Top achievements
Rank 1
Answers by
Vladimir Stoyanov
Telerik team
n/a
Top achievements
Rank 1
Share this question
or