输入3个字符后如何在autocompletebox中建议?

时间:2016-09-07 09:13:17

标签: wpf vb.net telerik autocompletebox

我使用telerik autocompletetextbox来建议正在运行的匹配单词。但我的要求是在输入超过2个字符时开始建议。有人可以帮我解决这个问题吗?

我遵循的代码:

<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"/>

在代码背后,

acbCustomerCd.ItemsSource = dtCustomerCd.DefaultView

4 个答案:

答案 0 :(得分:0)

为了实现这一点,您必须创建一个派生自FilteringBehavior类的自定义类,覆盖FindMatchingItems并仅在搜索字符串超过3个字符时返回项目。在此之后,您可以在xaml中初始化新类并将其分配给RadAutoCompleteBox。

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

...

<telerik:RadAutoCompleteBox ItemsSource="{Binding Items}" DisplayMemberPath="Name" FileringBehavior="{StaticResource  CustomFilteringBehavior}" />

答案 1 :(得分:0)

在此控件的Ajax版本中,我们MinFilterLength添加了此行为,您可以在此ASP.NET AutoCompleteBox DEMO中看到。

用于ASP.NET AJAX Q3 2013版本的Telerik®UI介绍:

  • MinFilterLength - 在控件启动对其DataSource的请求之前设置键入文本的最小长度。

答案 2 :(得分:0)

我不知道telerik是什么,但是如果你想运行一个自动完成的过程,你可以这样做。

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

答案 3 :(得分:0)

您可以使用MinFilterLength属性。

MinFilterLength = "2"