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

11 posts, 0 answers
  1. Andrew
    Andrew avatar
    39 posts
    Member since:
    Feb 2011

    Posted 08 May 2013 Link to this post

    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?
  2. Andrew
    Andrew avatar
    39 posts
    Member since:
    Feb 2011

    Posted 09 May 2013 Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 13 May 2013 Link to this post

    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.

  5. Patrick McBride
    Patrick McBride avatar
    3 posts
    Member since:
    Jul 2009

    Posted 30 May 2013 Link to this post

    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.
  6. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 31 May 2013 Link to this post

    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.

  7. Barnes
    Barnes avatar
    17 posts
    Member since:
    May 2012

    Posted 21 Nov 2013 Link to this post

    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..
  8. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 21 Nov 2013 Link to this post

    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 >>
  9. Ramon
    Ramon avatar
    11 posts
    Member since:
    Aug 2012

    Posted 29 Dec 2013 Link to this post

    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();
    }
  10. Anthony
    Anthony avatar
    13 posts
    Member since:
    Aug 2014

    Posted 03 Sep 2014 in reply to Ramon Link to this post

    Ramon - that worked perfectly. Thank you so much!
  11. kidanemiriam fikadu
    kidanemiriam fikadu avatar
    1 posts
    Member since:
    Mar 2016

    Posted 30 Mar Link to this post

    Have this bug fixed now?
  12. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 30 Mar Link to this post

    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.
Back to Top
UI for WPF is Visual Studio 2017 Ready