how to suggest in autocompletebox after entered 3 characters?

1.1k Views Asked by At

I used telerik autocompletetextbox to suggest matched words which is working. But my requirement is to start suggesting when more than 2 characters entered. Can anyone please help me to fix this issue?

Code i followed:

<telerik:RadAutoCompleteBox x:Name="acbCustomerCd" Width="203" Height="30" ItemsSource="{Binding}" DisplayMemberPath="AccountNum" TextSearchPath="AccountNum" AutoCompleteMode="Suggest" TextSearchMode="Contains"  Margin="1,0,5,0" BorderBrush="#ffcccccc" SelectionMode="Single" TabIndex="109" KeyboardNavigation.TabNavigation="Local"/>

In code behind,

acbCustomerCd.ItemsSource = dtCustomerCd.DefaultView
4

There are 4 best solutions below

1
Pratik Parikh On

In order to achieve this you will have to create a custom class deriving from the FilteringBehavior class, override the FindMatchingItems and return items only if the search string is more than 3 characters. After this you can initialize the new class in xaml and assign it to the RadAutoCompleteBox.

<Window.Resources>
   <telerik:CustomFilteringBehavior x:Key="CustomFilteringBehavior" />
</Window.Resources>

...

<telerik:RadAutoCompleteBox ItemsSource="{Binding Items}" DisplayMemberPath="Name" FileringBehavior="{StaticResource  CustomFilteringBehavior}" />
0
Drag and Drop On

In the Ajax version of this control we have MinFilterLength which adds this behavior, as you can see in this ASP.NET AutoCompleteBox DEMO.

The Telerik® UI for ASP.NET AJAX Q3 2013 release introduced:

  • MinFilterLength - Sets the minimum length of the typed text before the control initiates a request for its DataSource.
0
ASH On

I have no idea what telerik is, but if you want to run an auto-complete process, you can do it like this.

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports System.Data.SqlClient

Namespace WindowsFormsApplication4

    Public Class Form1
        Inherits Form

        Public Sub New()
            MyBase.New
            InitializeComponent
            Me.initializeFields
            Me.loadCustomerFromNorthwindDbToDgv1
        End Sub

        Private CustomerId As DataGridViewTextBoxColumn

        Private CompanyName As DataGridViewTextBoxColumn

        Private Address As DataGridViewTextBoxColumn

        Private Sub initializeFields()
            Me.CustomerId = New DataGridViewTextBoxColumn
            Me.CustomerId.Name = "CustomerID"
            Me.CustomerId.DataPropertyName = "CustomerID"
            Me.dataGridView1.Columns.Add(Me.CustomerId)
            Me.CompanyName = New DataGridViewTextBoxColumn
            Me.CompanyName.Name = "CompanyName"
            Me.CompanyName.DataPropertyName = "CompanyName"
            Me.dataGridView1.Columns.Add(Me.CompanyName)
            Me.Address = New DataGridViewTextBoxColumn
            Me.Address.Name = "Address"
            Me.Address.DataPropertyName = "Address"
            Me.dataGridView1.Columns.Add(Me.Address)
        End Sub

        Private dv As DataView

        Private Sub loadCustomerFromNorthwindDbToDgv1()
            Dim conConnect As SqlConnection = New SqlConnection("Data Source = EXCEL-PC; Database = 'Northwind.MDF'; Integrated Security = true")
            Try 
                Dim dAdapter As SqlDataAdapter = New SqlDataAdapter("SELECT CustomerID, CompanyName, Address FROM Customers ", conConnect)
                Dim DS As DataSet = New DataSet
                Dim bs As BindingSource = New BindingSource
                dAdapter.Fill(DS, "dsCustomer")
                Me.dataGridView1.AutoGenerateColumns = false
                Dim dt As DataTable = DS.Tables("dsCustomer")
                bs.DataSource = DS.Tables("dsCustomer")
                Me.dv = New DataView(DS.Tables("dsCustomer"))
                Me.dataGridView1.DataSource = bs
            Catch ex As Exception
                MessageBox.Show(ex.ToString)
            End Try

        End Sub

        'will do the search for CompanyName name everytime you type in @ the textbox search
        Private Sub textBox1_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
            Me.dv.RowFilter = ("CompanyName like '%' + '"  _
                        + (textBox1.Text + "' + '%' "))
            Me.dataGridView1.DataSource = Me.dv
        End Sub

        Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
            ' TODO: This line of code loads data into the 'northwindDataSet.Customers' table. You can move, or remove it, as needed.
            Me.customersTableAdapter.Fill(Me.northwindDataSet.Customers)
        End Sub
    End Class
End Namespace
0
Lekshmipriya On

You can use MinFilterLength property.

MinFilterLength = "2"