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

Prepoulate and receive all selected items

4 Answers 300 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Bjoern
Top achievements
Rank 1
Bjoern asked on 26 Apr 2016, 12:48 PM

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 ? 

4 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 27 Apr 2016, 11:43 AM
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.
0
JeffSM
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 10 Oct 2018, 05:24 PM

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.

0
Martin Ivanov
Telerik team
answered on 11 Oct 2018, 09:19 AM
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.
0
Ciupaz
Top achievements
Rank 2
Veteran
answered on 25 Jun 2020, 05:36 AM

In my aspx Page I have a button, and on the event click of this button I need to get the list (of strings) of all selected items keys in my RadAutoCompleteBox.

How can I make this?

 

L.

Tags
AutoCompleteBox
Asked by
Bjoern
Top achievements
Rank 1
Answers by
Yana
Telerik team
JeffSM
Top achievements
Rank 2
Iron
Veteran
Iron
Martin Ivanov
Telerik team
Ciupaz
Top achievements
Rank 2
Veteran
Share this question
or