I have a form with a listbox and several textboxes. When I input data in the
textboxes and click the menu I have created the aircraftId should appear in
the listbox and link the data form the other textboxes with the aircraftId. So if I have three AircraftId's when I highlight one the data recorded when I first clicked the menu with that aircraftID populates the textboxes. I have gotten the aircraftId to appear in the listbox put can't get the textboxes to be populated. Here is the code I have:

Private Sub mmuRecordSaveArrival_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mmuRecordSaveArrival.Click
Dim newItemText As String = txtAircraftID.Text
Me.lstAircraftID.Items.Add(newItemText)

This form is to test a class I created, and imported that class to the main form,so everthing is declared in the class.

I would use a couple of arrays. I'd use 1 to store the ID, and however many others for each of the textbox's. So, if you have 3 text boxes, (not including the ID) you would have 4 arrays. 1 for each text box and 1 for the ID. Then, when they click the listbox, figure out which item was selected, and pull that up in the other arrays. Does, that make sense?

Could you please show me an example.

I'm not sure what changes you'll have to make for use in .NET, but the basic code would be something like this:

In The Form Level Declarations:

' /* Dimension Variables */
Dim counter
Dim newItemText() As String 
Dim pilotname() as string
Dim planetype() as string

Then in your form load:

' /* Set counter to 0 (start of array) */
counter = 0

And In Your Click Event (Or wherever):

' /* Set The Indices Of The Array's To The Value Of counter */
redim newItemText(counter)
redim pilotname(counter)
redim planetype(counter)

' /* Set The Array's Current Indice To The Values In The Textbox's */
newItemText(counter) = txtAircraftID.Text
pilotname(counter) = text1.text
planetype(counter) = text2.text

' /* Add The Item To The ListBox */
Me.lstAircraftID.Items.Add(newItemText(counter))

' /* Increment (add one to) The Counter Variable (So We Don't Over-Write Our Array) */
counter = counter + 1

Then, Whenever You click inside the listbox

' /* Set The Values Of The Textbox's To The Array's Indices Of The Index Selected IN The listbox */
txtaircraftID.Text = newItemText(lstAircraftID.SelectedIndex)
text1.text = pilotname(lstAircraftID.SelectedIndex) 
text2.text = planetype(lstAircraftID.SelectedIndex)

Or Something Like that. Let me know if that works for you.

I'm very new at vb.net your explanation was kind of confusing to me. Do you think there is a way to do it without using an array?

Not that I know of.... Unless You are storing these in a file.

Thanks for your help I'll keep trying to figure it out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.