Wayne Cornish
Wayne Cornish

Reputation: 635

How do you get the selected item from a Silverlight AutoCompleteBox?

I'm hopefully missing something extremely obvious here, but for the life of me I can't figure this out.

I have an AutoCompleteBox control that is retrieving results by way of an asynchronous call, although I can't find a reliable way in which to know when a user has selected an option from the list of returned values. I've tried hooking into the SelectionChanged event, but that fires on every movement within the autocomplete's drop down list, when what I actually want to know is when a user has definitively said "Hey, that's the item I want!" by either clicking it, or selecting it with the return key.

Any advice would be greatly appreciated as this is starting to drive me a tad crazy now. =)

Thanks

P.S. The SelectionChanged event arguments provide AddedItems and RemovedItems, but don't give any direct indication of the type of selection I'm looking for.

Upvotes: 2

Views: 2207

Answers (2)

Tony L.
Tony L.

Reputation: 19406

If you are using the Telerik AutoCompleteBox, perhaps the "OnEntryAdded" event is what you are looking for. I see this question was asked over 4 years ago so perhaps this event didn't exist back then. I just updated to the latest update of Telerik controls (2014 Q2). Here's a quick example. I removed the properties that we're not discussing here to clean it up but, obviously, those will need to be added back in unless you're setting them in code (e.g. DataSourceID).

Source Page:

<telerik:RadAutoCompleteBox ID="RadAutoCompleteBox1" runat="server" OnEntryAdded="RadAutoCompleteBox1_EntryAdded" >
</telerik:RadAutoCompleteBox>

Test Code (in VB):

   Protected Sub RadAutoCompleteBox1_EntryAdded(sender As Object, e As AutoCompleteEntryEventArgs)
        MsgBox(e.Entry.Text)   'This is just to show you the DataValueField in your dev 
        MsgBox(e.Entry.Value)  'This is just to show you the DataTextField in your dev
        racbCustomer.Entries.Clear()  'This will wipe out the selection(s)
   End Sub

Upvotes: 0

AnthonyWJones
AnthonyWJones

Reputation: 189457

There isn't a specific event that indicates that the used has specifically plumped for an option rather then merely browsing.

For you scenario the closest you can get is DropDownClosed or even LostFocus events then access the SelectedItem property.

Upvotes: 1

Related Questions