输入任何字符时,我需要自动填充文本框。 对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中不存在时,textBox保持为空并且我输入的字符也被删除
我选择了AutoCompleteMode为Suggest,AutoCompleteMode为CustomSource
任何人都可以解释我做错了什么。
编辑:如果我使用另一个文本框的按键事件说TextBox1和自动填充FirstNamePri frrom TextBox1事件它的工作原理。它应该适用于FirstNamepri的keyPress
由于
答案 0 :(得分:0)
你可以试试这样的事情
Dim textParam = FirstNamePri.Text + "%"
Dim search As ArfDynamicsDataSet.QuickSearchDataTable = _
Me.QuickSearchTableAdapter1.GetDataByFirstName(textParam)
答案 1 :(得分: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