MarkFirstMatch is auto completing sentences in combobox

2 posts, 0 answers
  1. Justin
    Justin avatar
    11 posts
    Member since:
    Jul 2012

    Posted 29 Nov 2012 Link to this post

    I have a Rad combo box that when you type it starts completing sentences instead of just marking the one that is most similar.

    <telerik:RadComboBox ID="rcbSiteSearch" runat="server" Width="190px" Height="100px" EnableLoadOnDemand="True" ShowMoreResultsBox="true" MarkFirstMatch="true" AllowCustomText="true" EnableVirtualScrolling="true" OnItemsRequested="rcbSiteSearch_ItemsRequested" />

    Protected Sub rcbSiteSearch_ItemsRequested(ByVal sender As Object, ByVal e As RadComboBoxItemsRequestedEventArgs)
            Const ItemsPerRequest As Integer = 5
            Dim data As DataTable = GetSiteName(e.Text)
            Dim itemOffset As Integer = e.NumberOfItems
            Dim endOffset As Integer = Math.Min(itemOffset + ItemsPerRequest, data.Rows.Count)
            e.EndOfItems = endOffset = data.Rows.Count
            For i As Integer = itemOffset To endOffset - 1
                rcbSiteSearch.Items.Add(New RadComboBoxItem(data.Rows(i)("name").ToString(), data.Rows(i)("value").ToString()))
            e.Message = GetStatusMessage(endOffset, data.Rows.Count)
        End Sub
        Private Shared Function GetSiteName(ByVal text As String) As DataTable
            Dim StateCode As String = "pa"
            Dim connectionString As String = *Connection String*
            Dim QueryStr As String = *QUERY*
            Dim adapter As New SqlDataAdapter(QueryStr,connectionString)
            Dim Data As New DataTable()
            Catch ex As Exception
                Call MsgBox(String.Format("Unexpected Error: {0}", ex.ToString()), 0, "Unexpected Search Error")
            End Try
            Return Data
        End Function
        Private Shared Function GetStatusMessage(ByVal offset As Integer, ByVal total As Integer) As String
            If total <= 0 Then
                Return "No matches"
            End If
            Return [String].Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", offset, total)
        End Function
  2. Boyan Dimitrov
    Boyan Dimitrov avatar
    2062 posts

    Posted 04 Dec 2012 Link to this post

    Hello Justin,

    In order to achieve the desired functionality I would recommend that you use Filter="StartsWith" or Filter="Contains" instead of MarkFirstMatch property. The StartsWith value will mark and filter all items whose text property starts with the typed text. The Contains value will filter the Items and provide a list with the ones whose text is typed in the input of the control. Please check our online demo that shows the functionality.

    All the best,
    Boyan Dimitrov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top