如何在VB中过滤组合框值 [英] how to filter the combobox values in vb

查看:79
本文介绍了如何在VB中过滤组合框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是VB的新手,我有政策编号。输入我的保单编号的前四位数后,VB中的组合框就会填充,但是,如果我继续输入数字,它将覆盖我已经输入的数字并清除下拉列表,就像选择要输入的新4个数字一样。我想实现一种情况,在此情况下,我继续输入policyno时,将输入前4个数字来填充下拉列表,而不会搜索下拉列表中的值。

I am new to VB.I have a policy no. combobox in VB which populates after I enter first four digits of the policy no.However, if I continue to type the number it overwrites what I have already typed and wipes out the dropdown list, as if selecting for the new 4 numbers I typed.I Want to acheive a scenario where I will enter the first 4 numbers to populate the dropdown after that as i go on entering the policyno the values in the dropdown list get searched.

EG:政策编号:969003648,当我键入9690时,下拉列表中的填充号为969000001,现在我继续键入969003等等,搜索到的值仅限于政策编号为969003的起始值...请协助

E.G:Policy number: 969003648, as I type 9690 the drop down is filled in with the policy no's starting from 969000001, now as I go on typing the values as 969003 etc the searched values gets limited to the policy no's having 969003 as starting values...Please assist

我的代码:

Private Sub PolicyNo_KeyDown(KeyCode As Integer, Shift As Integer)

If KeyCode = 46 Or KeyCode = 8 Then
Me.PolicyNo.value = ""
Else

If Len(Me.PolicyNo.Text) >= 4  Then
Me.PolicyNo.RowSource = ""
Call ReloadPolicyNo(Nz(Me.PolicyNo.Text, ""))

Function ReloadPolicyNo(sPolicyNo As String)

Me.PolicyNo.RowSource = "SELECT Inventory.PolicyNo FROM Inventory " & _
                          "WHERE Left(Inventory.PolicyNo," & Len(Me.PolicyNo.Text) & ")  = '" & Me.PolicyNo.Text & "' order by Inventory.PolicyNo"
End Function


推荐答案

最好在这里使用 DataView ,我将 DataTable 声明为类变量

It's better to use DataView here , I declared DataTable as class Variable.

Dim dt as DataTable

从数据库中获取所有数据并将其绑定到声明的 DataTable ,此 DataTable 进一步添加到 DataView 并使用 RowFilter 过滤 DataView
Compay_Type 是我的 DataTable 中的列之一,下面的代码将过滤 DataView 并在列 Company_Type = 1

Fetched All the data from database and bind it to declared DataTable, This DataTable further added to DataView and use RowFilter to filter DataView. Compay_Type is one of the column in my DataTable Below code will filter DataView and bind data where column Company_Type=1

            Dim dvComp As New DataView(dt)
            dvComp.RowFilter = "Company_Type=1"
            ComboBox1.DisplayMember = "CompanyName"
            ComboBox1.ValueMember = "CompanyID"
            ComboBox1.DataSource = dvComp

要删除过滤器,只需使用 dvComp.RowFilter = Nothing

To remove Filter just use dvComp.RowFilter = Nothing

这篇关于如何在VB中过滤组合框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆