在vb中自动填充textBox [英] autofill textBox in vb

查看:266
本文介绍了在vb中自动填充textBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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)

私人子FirstNamePri_KeyPress(ByVal发件人为对象,ByVal e为 System.Windows.Forms.KeyPressEventArgs)处理FirstNamePri.KeyPress

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

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

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

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

I have selected AutoCompleteMode to Suggest and AutoCompleteMode to CustomSource

任何人都可以解释我在做什么错.

Can anyone explain what i am doing wrong.

如果我使用另一个文本框的keypress事件,请说TextBox1并自动填充FirstNamePri frrom TextBox1事件,它可以正常工作.它应该可以在FirstNamepri的keyPress上工作

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

谢谢

推荐答案

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

这篇关于在vb中自动填充textBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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