AutoCompleteBox: Determine if text came from AutoCompleteItems

2 posts, 1 answers
  1. John
    John avatar
    14 posts
    Member since:
    Apr 2013

    Posted 18 Apr 2013 Link to this post

    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.


  2. Answer
    Stefan avatar
    2911 posts

    Posted 23 Apr 2013 Link to this post

    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
           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
                Return _id
            End Get
            Set(ByVal value As Integer)
                _id = value
            End Set
        End Property
        Private _name As String
        Public Property Name() As String
                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.

    the Telerik team
    WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
Back to Top