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

AutoCompleteBox: Determine if text came from AutoCompleteItems

1 Answer 68 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 18 Apr 2013, 02:30 PM
Hey Telerik!

I would like to determine if a newly created text block was from the autocompleteitems list or not.

I noticed that your AutoCompleteItems used a RadListDataItemCollection.  Is it possible to use a collection of objects ?

If not, I will be adding items to the AutoCompleteItems in the form of 

items.Add(New RadListDataItem("Joe Smith", "GUID HERE"))

I was assuming the CreateTextBlock event could be used to determine if there was a GUID value attached or not.  I could use this as a way to determine if the item was from the AutoCompleteItems.  I am not sure how to get the data value for the text block element or hopefully custom class for the newly created block.

Thanks





1 Answer, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 23 Apr 2013, 08:00 AM
Hi John,

Thank you for writing.

To check whether an item is from the auto complete items, you can use the CreateTextBlock event and perform the desired verification:
Private Sub RadAutoCompleteBox1_CreateTextBlock(sender As Object, e As CreateTextBlockEventArgs) Handles RadAutoCompleteBox1.CreateTextBlock
       Dim index As Integer = RadAutoCompleteBox1.AutoCompleteItems.IndexOf(e.Text)
 
       If index > -1 Then
           Console.WriteLine(RadAutoCompleteBox1.AutoCompleteItems(index).Value)
       End If
   End Sub

The code above, also demonstrates how to access the selected item Value.

In order to use a collection of objects, you should use the AutoCompleteDataSource property of the control:
Dim list As New List(Of MyObject)
 list.Add(New MyObject() With {.ID = 1, .Name = "Name 1"})
 list.Add(New MyObject() With {.ID = 2, .Name = "Name 2"})
 list.Add(New MyObject() With {.ID = 3, .Name = "Name 3"})
 
 RadAutoCompleteBox1.AutoCompleteDataSource = list
 RadAutoCompleteBox1.AutoCompleteDisplayMember = "Name"

Class MyObject
    Private _id As Integer
    Public Property ID() As Integer
        Get
            Return _id
        End Get
        Set(ByVal value As Integer)
            _id = value
        End Set
    End Property
 
    Private _name As String
    Public Property Name() As String
        Get
            Return _name
        End Get
        Set(ByVal value As String)
            _name = value
        End Set
    End Property
End Class

I hope that you find this information useful. Let us know if you need anything else.
 

Greetings,
Stefan
the Telerik team
WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
Tags
AutoCompleteBox
Asked by
John
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or