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

MarkFirstMatch is auto completing sentences in combobox

1 Answer 36 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Justin asked on 29 Nov 2012, 10:07 PM
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

1 Answer, 1 is accepted

Sort by
Boyan Dimitrov
Telerik team
answered on 04 Dec 2012, 03:36 PM
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.
Asked by
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Share this question