vb中的自动填充文本框 [英] autofill textBox in vb

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

问题描述

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

SELECT firstNamePri FROM Customer WHERE (firstNamePri LIKE @firstName)

<块引用>

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

 将 txtItems 变暗为新的 AutoCompleteStringCollectionDim 搜索 As ArfDynamicsDataSet.QuickSearchDataTable = _Me.QuickSearchTableAdapter1.GetDataByFirstName(FirstNamePri.Text+"%")Dim dbValues 作为字符串For each row As DataRow In search.RowsdbValues = row("firstNamePri").ToString()dbValues = dbValues.ToLower()txtItems.Add(dbValues)下一个FirstNamePri.AutoCompleteCustomSource = txtItems结束子

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

我已选择 AutoCompleteMode 为 Suggest,AutoCompleteMode 为 CustomSource

谁能解释一下我做错了什么.

如果我使用另一个文本框的按键事件说 TextBox1 和 autofill FirstNamePri frrom TextBox1 事件它工作.它应该适用于 FirstNamepri 的 keyPress

谢谢

解决方案

Public Function FetchProductSpareList(prefixText As String) As String()Dim dbinventory 作为新 DCInventoryNewDataContext()Dim CompanyId As Integer = Convert.ToInt32(System.Web.HttpContext.Current.Session("CompanyID").ToString())昏暗的产品名称 = ( _在 S.ProductId = P.id _ 上的 dbinventory.Products 中加入 P加入 C 在 dbinventory.SpareReceiptCodes On S.Id = C.StoreId _其中 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对于每个产品作为产品名称中的 varitems.SetValue(Product.ProductName, i)我 += 1下一个退换货品结束函数

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

解决方案

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中的自动填充文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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