1

输入任何字符时,我需要自动填充文本框。Me.QuickSearchTableAdapter1.GetDataByFirstName(FirstNamePri.Text) 的查询是

SELECT        firstNamePri FROM      Customer WHERE        (firstNamePri LIKE @firstName)

Private Sub FirstNamePri_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) 处理 FirstNamePri.KeyPress

    Dim txtItems As New AutoCompleteStringCollection
    Dim search As ArfDynamicsDataSet.QuickSearchDataTable = _
    Me.QuickSearchTableAdapter1.GetDataByFirstName(FirstNamePri.Text+"%")

    Dim dbValues As String

    For Each row As DataRow In search.Rows

         dbValues = row("firstNamePri").ToString()
        dbValues = dbValues.ToLower()
        txtItems.Add(dbValues)


    Next

    FirstNamePri.AutoCompleteCustomSource = txtItems

End Sub

当我输入一个字符并且该字符在 db 中不存在时,文本框保持为空,并且我输入的字符也被删除

我选择了 AutoCompleteMode 来建议和 AutoCompleteMode 到 CustomSource

谁能解释我做错了什么。

编辑:如果我使用另一个文本框的按键事件说 TextBox1 并从 TextBox1 事件中自动填充 FirstNamePri 它可以工作。它应该在 FirstNamepri 的 keyPress 上工作

谢谢

4

2 回答 2

0
Public Function FetchProductSpareList(prefixText As String) As String()
    Dim dbinventory As New DCInventoryNewDataContext()
    Dim CompanyId As Integer = Convert.ToInt32(System.Web.HttpContext.Current.Session("CompanyID").ToString())

    Dim ProductNames = ( _
    Join P In dbinventory.Products On S.ProductId = P.id _
    Join C In dbinventory.SpareReceiptCodes On S.Id = C.StoreId _
    Where P.CompanyID = CompanyId AndAlso C.Active = True AndAlso _
                      P.ProductName.StartsWith(prefixText)).Distinct()
    Dim items As String() = New String(ProductNames.Count() - 1) {}
    Dim i As Integer = 0
    For Each Product As var In ProductNames
        items.SetValue(Product.ProductName, i)
        i += 1
    Next
    Return items
End Function
于 2012-11-24T10:53:53.317 回答
0

你可以试试这样的

Dim textParam = FirstNamePri.Text + "%"
Dim search As ArfDynamicsDataSet.QuickSearchDataTable = _
          Me.QuickSearchTableAdapter1.GetDataByFirstName(textParam)
于 2012-11-24T10:06:10.653 回答