0

I have 5 text boxes: Phone, Pager, cell, voicemail, and email. They need to auto populate when a name is selected from a combo box. Data used to populate both the combo boxes, and text boxes come from the same text file.

An example of what the data looks like in the text file:

Mickey

204-5555

666-555

777-7777

888-8888

23w@hhh.ra

I've gotten to the point where I can load the names from the text file to the ComboBox, using the code provided below.

But How do I get the text boxes to populate, after I’ve selected a name from the combo box?

Public Class BlackBookLookup

Private fileName As String
Dim FileLines As New List(Of String)

Private Sub mmuOpenTool_Click(sender As Object, e As EventArgs) Handles mmuOpenTool.Click

    Dim BlackBookDialogResult As DialogResult

    Using fileChooser As New OpenFileDialog()
        BlackBookDialogResult = fileChooser.ShowDialog()
        fileName = fileChooser.FileName
    End Using

    If BlackBookDialogResult <> DialogResult.Cancel Then
        MessageBox.Show(OpenFileDialog1.SafeFileName)

    End If

    If IO.File.Exists(fileName) Then
        FileLines.AddRange(IO.File.ReadAllLines(fileName))
        If FileLines.Count > 1 Then

            For x = 0 To FileLines.Count - 1 Step 6
                chooseNameComboBox.Items.Add(FileLines(x + 0))
            Next

        End If

    End If
DSQLJ
  • 1
  • 3
  • 1
    I'd read the data into a `List(of T)` so the related data stays together. Use it as a datasource for the CBO; after they pick, use the properties of the `SelectedItem` to populate the text controls – Ňɏssa Pøngjǣrdenlarp Sep 04 '17 at 18:21
  • Never used list of T before, wouldn't know where to start. – DSQLJ Sep 04 '17 at 19:18
  • 2
    Now's your chance to learn something and improve your skillset. **[Five Minute Intro to Classes and Lists](http://stackoverflow.com/a/34164458/1070452)** – Ňɏssa Pøngjǣrdenlarp Sep 04 '17 at 19:23
  • Still not sure how that applies here. Would it be like: "myDGV.DataSource = filename"? – DSQLJ Sep 05 '17 at 16:13
  • As the link clearly explains towrds the end `A List(Of T) can be used as a DataSource for some controls:`. So, your `List(of Contact)` would be the datasource. Given a `List(of T)` you could also serialize it for saving. 1 line of code to save the entire typed collection. – Ňɏssa Pøngjǣrdenlarp Sep 05 '17 at 16:20
  • Would it be possible to bind the textboxes to the combo box via the data source window? – DSQLJ Sep 05 '17 at 16:44
  • No because the CBO is nto a datasource. But you could wrap you shiny new List(of T) in a binding source and use that to drive the other controls. Please read [ask] and take the [tour]. This is not a tutorial site. Vague things like `would it be possible` are too broad for here. You are expected to do your own research – Ňɏssa Pøngjǣrdenlarp Sep 05 '17 at 17:39
  • I appreciate your patients regarding the aside question, I wanted to ask because that was the answer I just received from my instructor. I'll go else ware to find a solution. – DSQLJ Sep 05 '17 at 17:51

0 Answers0