Prepoulate and receive all selected items

4 posts, 0 answers
  1. Bjoern
    Bjoern avatar
    1 posts
    Member since:
    Apr 2016

    Posted 26 Apr 2016 Link to this post

    Hi there, 

    I am currently testing the autocompletebox in our project and I am having some troubles understanding certain parts of it. I had a look at the documentation and the examples, but they have not really helped me. 

     

    Our scenario is simple: 

    A user wants to send a message to another user. The ACB is used to search for the contact and add it to the recipients list. (At least thats the plan)

    We have an ObservableCollection holding all Contacts of a user. I have bound that to the ItemsSource of the ACB. 

     

    <telerik:RadAutoCompleteBox x:Name="txtSearchBoxCC"
                                ItemsSource="{Binding ContactsList}"
                                DisplayMemberPath="Fullname" />

    The ACB works as intended, I can search and select contacts as I wish. 

    My problem is, that I would just like to check for all the selected Items in the ACB by the time the user hits "send". 

    Also, how can I prepopulate the Textbox with some of the Items in the ItemsSource ? 

  2. Yana
    Admin
    Yana avatar
    4914 posts

    Posted 27 Apr 2016 Link to this post

    Hi Bjoern,

    You could use SelectedItems property of RadAutoCompleteBox to get/set the currently selected Contacts in the concrete case. SelectedItems could be bound to a collection in the ViewModel in the same way as ItemSource and  this collection could be populated with some items from the ContactsList collection, so that they are pre-selected in the AutoCompleteBox. Here is a quick example:

    this.SelectedContacts = new ObservableCollection<Contact>()
    {
       ContactsList[0],
       ContactsList[1]
    };

    <telerik:RadAutoCompleteBox ItemsSource="{Binding ContactsList}"
         DisplayMemberPath="Fullname"
         SelectedItems="{Binding SelectedContacts}" />

    I hope this will be helpful.

    Regards,
    Yana
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. JeffSM
    JeffSM avatar
    42 posts
    Member since:
    May 2014

    Posted 10 Oct 2018 in reply to Yana Link to this post

    I DONT KNOW HOW READ THE FIRST SELECTED ITEN? WHY HAS NO DOCUMENTATION ABOUT HOW READ AN ITEM?

    PLEASE, HOW DO I READ THE SELECTED ITENS, ON WPF DEMO DON'T EXPLAIN TOO.

  4. Martin Ivanov
    Admin
    Martin Ivanov avatar
    2240 posts

    Posted 11 Oct 2018 Link to this post

    Hello Jefferson,

    May I ask you to elaborate a bit more on your requirement? What you mean by saying that you want to read the first selected item?

    Note that if you want to get the first selected item you can use the System.Linq extension methods to get the first element from the IEnumerable that stands behind the SelectedItems property. For example:
    var firstSelectedItem = this.autoCompleteBox.SelectedItems.OfType<Contact>().FirstOrDefault();
    if (firstSelectedItem != null)
    {
        // do something
    }
    I've attached a small example showing this approach. I hope it helps.

    Regards,
    Martin Ivanov
    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