简体   繁体   English

VB.net 链接两个自动完成文本框

[英]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它只是一些简单的设置:

  1. Add 2 combo box, one for Code and another for Name .添加 2 个组合框,一个用于Code ,另一个用于Name
  2. Set DataSource of both combo boxes to the same list.将两个组合框的DataSource设置为相同的列表。
  3. Set DisplayMember of one to Code property and another to Name property.将一个的DisplayMember设置为Code属性,将另一个设置为Name属性。
  4. Set AutoCompleteSource of both to ListItems .将两者的AutoCompleteSource设置为ListItems
  5. Set 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM