[英]VB.net linking two autocomplete textbox
I have two autocomplete textboxes.我有两个自动完成文本框。 One is for customer name and the other is for customer code.
一个用于客户名称,另一个用于客户代码。 I have set up the Autocomplete for the customer and customer code textboxes using this code:
我已经使用以下代码为客户和客户代码文本框设置了自动完成功能:
Customer AutoComplete客户自动完成
Dim ds As DataSet = obtainCustomerData()
Dim i As Integer
For i = 0 To ds.Tables(0).Rows.Count - 1
CustName.Add(ds.Tables(0).Rows(i)("name").ToString().ToUpper)
Next
CustomerNameTB.AutoCompleteSource = AutoCompleteSource.CustomSource
CustomerNameTB.AutoCompleteCustomSource = CustName
CustomerNameTB.AutoCompleteMode = AutoCompleteMode.Suggest
Customer Code Autocomplete客户代码自动完成
Dim ds As DataSet = obtainCustomerCodeData()
Dim i As Integer
For i = 0 To ds.Tables(0).Rows.Count - 1
CustCode.Add(ds.Tables(0).Rows(i)("code").ToString().ToUpper)
Next
CodeTB.AutoCompleteSource = AutoCompleteSource.CustomSource
CodeTB.AutoCompleteCustomSource = CustCode
CodeTB.AutoCompleteMode = AutoCompleteMode.Suggest
Now I want the end user to begin typing in either textbox, however if they select a customer based on name I want it to bring through the code on the other text box and if they begin typing a code I would like it auto populating the name.现在我希望最终用户开始在任一文本框中输入,但是如果他们根据名称选择客户,我希望它通过另一个文本框中的代码,如果他们开始输入代码,我希望它自动填充名称.
How would I go about this?我该怎么办?
If you use ComboBox
instead of TextBox
it would be just some simple settings:如果您使用
ComboBox
而不是TextBox
它只是一些简单的设置:
Code
and another for Name
.Code
,另一个用于Name
。DataSource
of both combo boxes to the same list.DataSource
设置为相同的列表。DisplayMember
of one to Code
property and another to Name
property.DisplayMember
设置为Code
属性,将另一个设置为Name
属性。AutoCompleteSource
of both to ListItems
.AutoCompleteSource
设置为ListItems
。AutoCompleteMode
of both to Suggest
.AutoCompleteMode
设置为Suggest
。 This way, each ComboBox
will act like an index for the list and when you select an item from one of them, the other one will select the same item.这样,每个
ComboBox
都将充当列表的索引,当您从其中一个中选择一个项目时,另一个将选择相同的项目。 One shows Code
and the other shows Name
.一个显示
Code
,另一个显示Name
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.