1

我是 VB 的新手。我有一个保单号。VB 中的组合框在我输​​入保单编号的前四位数字后填充。但是,如果我继续输入数字,它会覆盖我已经输入的内容并清除下拉列表,就像选择我输入的新 4 个数字一样。我想实现一个场景,我将输入前 4 个数字以填充下拉列表,然后我继续输入 policyno 下拉列表中的值被搜索。

EG:保单号:969003648,当我输入 9690 时,下拉列表中填充了从 969000001 开始的保单号,现在当我继续键入 969003 等值时,搜索的值被限制为以 969003 作为起始值的保单号...请协助

我的代码:

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
4

2 回答 2

0

为什么不使用组合框上的 Textchanged 事件来获取组合框中当前的内容?

例子

    'THIS FIRES WHEN TEXT IS ENTERED INTO THE COMBOBOX
Private Sub ComboBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.TextChanged

    'GET VALUE IN COMBOBOX
    Dim enteredText As String = ComboBox1.Text
    Dim strSelect As String = "select * from table where field like = '" & enteredText & "'%"

    'load COMBO BOX HERE

End Sub
于 2012-11-22T12:51:43.550 回答
0

最好在DataView这里使用,我声明DataTableclass Variable

Dim dt as DataTable

从数据库中获取所有数据并将其绑定到声明DataTable中,这DataTable进一步添加到过滤器中DataView使用。 是我下面的代码中的一列将过滤和绑定数据,其中列RowFilterDataViewCompay_TypeDataTableDataViewCompany_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

于 2017-05-04T02:00:41.710 回答