开发者

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

开发者 https://www.devze.com 2022-12-16 07:19 出处:网络
I\'m hopefully missing something extremely obvious here, but for the life of me I can\'t figure this out.

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'开发者_JAVA百科t give any direct indication of the type of selection I'm looking for.


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.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消