autofill textBox in vb

强颜欢笑 提交于 2019-12-24 11:11:04

问题


I need to autofill text box when any character is entered. The query for Me.QuickSearchTableAdapter1.GetDataByFirstName(FirstNamePri.Text) is

SELECT        firstNamePri FROM      Customer WHERE        (firstNamePri LIKE @firstName)

Private Sub FirstNamePri_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles 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

When I enter a character and that character is not present in db the textBox stays empty and the characters i enter are also being deleted

I have selected AutoCompleteMode to Suggest and AutoCompleteMode to CustomSource

Can anyone explain what i am doing wrong.

EDIT: If I use keypress event of another textbox say TextBox1 and autofill FirstNamePri frrom TextBox1 event it works. It should work on keyPress of FirstNamepri

Thanks


回答1:


You could try something like this

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



回答2:


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


来源:https://stackoverflow.com/questions/13540105/autofill-textbox-in-vb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!