Autocomplete combined with fulltext search

5 posts, 1 answers
  1. Thomas
    Thomas avatar
    13 posts
    Member since:
    Feb 2008

    Posted 10 Nov 2009 Link to this post


    I'm trying to realize some kind of article search in form of a text- or combobox. When the user enters some text, the autocompletion should perform a fulltext search for any matching article.

    The actual autocompletion only works like the string.StartsWith(...) function but I'd like to have something like the string.Contains(...) function.

    I tried to ralize it with a combobox that changes its ItemCollection on the TextChanged event:



    void radComboBox1_TextChanged(object sender, EventArgs e)



        var query = from s in _autoComplete.Keys  
                where s.Contains(radComboBox1.Text)  
                select s;  
        foreach (string art in query.ToArray())  
            radComboBox1.Items.Add(new RadComboBoxItem() { Text = art, Tag = _autoComplete[art] });  

    This work to the point where the user uses the arrow keys to navigate through the autocomplete list. This leads to an update and only one remaining option in the autocomplete list.

    Any suggestions? Is there a property for the autocomplete functionality I don't know?

    kind regards,
  2. Answer
    Deyan avatar
    2147 posts

    Posted 13 Nov 2009 Link to this post

    Hello Thomas,

    Thanks for writing.

    The reason for the undesired behavior that you experience is that when navigating through the items in the RadComboBox control, the TextChanged event is fired since the text is updated to reflect the currently selected item. The current implementation of this event in your code takes the text from the combo box (which will exactly match an item from the drop down), filters the options again, and thus only one item remains visible in the drop down.

    In this case, you can use the KeyPress event of the RadComboBox instead and then apply the filtering. The KeyPress event will not be fired when you navigate over the items in the drop down and therefore you will not face the issue described above.

    I hope this is helpful.

    You can write back anytime you need further assistance.

    All the best,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Thomas
    Thomas avatar
    13 posts
    Member since:
    Feb 2008

    Posted 17 Nov 2009 Link to this post

    Hello Deyan!

    Thanks for your help, the proposed solution works great!

    kind regards,
  4. NORIS
    NORIS avatar
    29 posts
    Member since:
    Jun 2009

    Posted 24 Feb 2010 Link to this post

    I would like to use this in VB.  I used the code convert and it does not like var as a type.
    Could you tell me how to fix this?


    Public Sub FilterList(ByVal cb As RadComboBox) 'use on KeyPress event



    'filter in list of combobox with Contains



    Dim query As var = From s In _autoComplete.Keys _



    Where s.Contains(cb.Text) _



    Select s





    For Each art As String In query.ToArray()



    New RadComboBoxItem())








    End Sub 'FilterList


  5. Nikolay
    Nikolay avatar
    1805 posts

    Posted 02 Mar 2010 Link to this post

    Hi NORIS,

    Var is a special keyword in C# and you can find additional information about it here. However, you do not need it in VB.NET and you can make a query as it is demonstrated in this article.

    Best wishes,
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top