简体   繁体   中英

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:

  1. Add 2 combo box, one for Code and another for Name .
  2. Set DataSource of both combo boxes to the same list.
  3. Set DisplayMember of one to Code property and another to Name property.
  4. Set AutoCompleteSource of both to ListItems .
  5. Set AutoCompleteMode of both to 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. One shows Code and the other shows Name .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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