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

Binding to SearchText, but also on selection of suggested entry...

10 Answers 638 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 08 May 2013, 02:41 PM
Just getting started on this control, and WPF in general, so I don't know if this is a WPF thing, or a Telerik thing, but the scenario is as follows:

I have an autocomplete box bound to a 'Countries' collection of 'Country' objects (Country is a string)
I want the user to be able to type in anything, but also select from a list of suggestions if there is one there after a partial typed entry. The list of countries might not contain the typed entry.


The trouble is - I can't get the SelectedItem and SearchText to bind to my MVVM objects SelectedCountry property at the same time.

This is the markup

  <telerik:RadAutoCompleteBox 
        x
:Name="AutoComp" 
        DisplayMemberPath
="Country" TextSearchPath="Country" 
        ItemsSource
="{Binding Countries, Mode=OneWay, Source=StaticResource Lookups}}" 
        SelectionMode
="Single" 
        SearchText
="{Binding MVVObject.SelectedCountry, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" 
  />

I've tried various binding statements for the SelectedItem property, but I'd have thought when the dropdown entry is clicked, and the text changes in the textbox, the SearchText would be updated, but actually, it doesn't. So if I type 'bul', then select Bulgaria from the dropdown, when I set focus to another control, 'bul' is what is INotified to my SelectedCountry property...

Am I missing something?

10 Answers, 1 is accepted

Sort by
0
Andrew
Top achievements
Rank 1
answered on 09 May 2013, 05:55 AM
http://www.telerik.com/community/forums/wpf/autocompletebox/databinding-to-radautocompletebox.aspx

This is the problem I'm having actually - but its seemingly not been fixed in 2013 Q1.
 
I'd propose simply having a 'Text' property as well as SearchText, which is the 'resolved' text set from either what is being typed if nothing is selected from the suggestions, or the suggestion in full if it is selected in the dropdown list.
0
Vladi
Telerik team
answered on 13 May 2013, 12:06 PM
Hi,

As the other post mentioned in the current version of the AutoComplateBox control there is a know issue that causes the SearchText property to not be updated after selection is made. When the issue is resolved this property will be updated to represent the selected item in the control which would cause the inputted text to not be available after selection. Could you describe to us in more details the cases in which being able to access that entered text would be useful in order for us to see all useful cases and possibly implement such functionality that will allow to access that text in the future versions of RadAutoComplateBox.

About your questions on how to add new items you could use the KeyDown event of the control and then in to code behind just add a new item if it doesn't exist in the ItemsSource collection. The next code snippet shows how the KeyDown should look like:
<telerik:RadAutoCompleteBox ItemsSource="{Binding Countries}"
                SelectionMode="Single"
                KeyDown="RadAutoCompleteBox_KeyDown_1"
                SelectedItem="{Binding SelectedCountry}"/>

and in the code behind:
private void RadAutoCompleteBox_KeyDown_1(object sender, KeyEventArgs e)
{
    var autoCompleteBox = sender as RadAutoCompleteBox;
    var inputText = autoCompleteBox.SearchText;
    var itemsSource = autoCompleteBox.ItemsSource as ObservableCollection<string>;
 
    if (e.Key == Key.Enter && !itemsSource.Contains(inputText))
    {
        itemsSource.Add(inputText);
        autoCompleteBox.ItemsSource = itemsSource;
        autoCompleteBox.SelectedItem = inputText;
    }
}

Hope this is helpful.

Kind regards,
Vladi
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Patrick McBride
Top achievements
Rank 1
answered on 30 May 2013, 10:06 PM
I have the same problem.  Would appreciate the ability to use the RadAutoCompleteBox as a suggested list of items but allow the user to enter anything and then databind to the selected value or entered value through one property.  Thanks.
0
Vladi
Telerik team
answered on 31 May 2013, 02:28 PM
Hello,

We will do our best to have the previously described behavior of the SearchText property fixed in one our future releases of RadControls.

Regards,
Vladi
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Barnes
Top achievements
Rank 1
answered on 21 Nov 2013, 10:28 AM
Has this been fixed yet?

This is an important feature. It would be common for a user to be presented with a list of possible suggestions for a particular value i.e. common entries, but choose to enter something different..
0
Vladi
Telerik team
answered on 21 Nov 2013, 01:20 PM
Hello,

Unfortunately the previously mentioned issue of the SearchText not getting updated after selection is made is still not resolved.

You can keep track of its status via our Pubic Issue Tracker System where when it is resolved its status will be updated. Here is a direct link to the mentioned issue. We apologize for any inconvenience that this may be causing.

Regards,
Vladi
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Ramon
Top achievements
Rank 1
answered on 29 Dec 2013, 02:18 PM
Here is a work around i used
in the Xaml i use lostFocus and the for autocomplete mode is suggest mode, middleNames is ObservableCollection<string>
<StackPanel Orientation="Vertical" >
               <Label Content="Middle Name" VerticalAlignment="Center"/>
               <telerik:RadAutoCompleteBox  SearchText="{Binding MiddleName, Mode=TwoWay}"
                                LostFocus="FillIt"
                                SelectionMode="Single" AutoCompleteMode="Suggest"
                                ItemsSource="{Binding MiddleNames}"
</
StackPanel>


back code ifSelectedItem is selected use it

private void FillIt(object sender, RoutedEventArgs e)
{
    var autoCompleteBox = sender as RadAutoCompleteBox;
     
    if (autoCompleteBox.SelectedItem != null)
        autoCompleteBox.SearchText = autoCompleteBox.SelectedItem.ToString();
}
0
Anthony
Top achievements
Rank 1
answered on 03 Sep 2014, 10:35 PM
Ramon - that worked perfectly. Thank you so much!
0
kidanemiriam fikadu
Top achievements
Rank 1
answered on 30 Mar 2016, 06:20 AM
Have this bug fixed now?
0
Yana
Telerik team
answered on 30 Mar 2016, 11:04 AM
Hello,

Yes, the discussed in this thread issue about the SearchText property of RadAutoCompleteBox is fixed, you can check it in our Feedback Portal at the following link:
http://feedback.telerik.com/Project/143/Feedback/Details/66932-searchtext-property-is-not-updated-when-an-item-is-selected

Regards,
Yana
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
AutoCompleteBox
Asked by
Andrew
Top achievements
Rank 1
Answers by
Andrew
Top achievements
Rank 1
Vladi
Telerik team
Patrick McBride
Top achievements
Rank 1
Barnes
Top achievements
Rank 1
Ramon
Top achievements
Rank 1
Anthony
Top achievements
Rank 1
kidanemiriam fikadu
Top achievements
Rank 1
Yana
Telerik team
Share this question
or