using SelectedIndexChanged

uncle55

Member
Joined
Jun 27, 2004
Messages
5
Location
Wisconsin
Programming Experience
Beginner
Can a code be created for the SelectedIndexChanged event to display information in other control instances when a user selects a item in the list box?
 

uncle55

Member
Joined
Jun 27, 2004
Messages
5
Location
Wisconsin
Programming Experience
Beginner
I have gotten the txtaircraftId to appear in the listbox by using this menu event:

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)

End Sub

When I highlight the aircraftId in the listbox it reappears in the aircraftID textbox I did that with this event statement:

Private Sub AircraftID_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstAircraftID.SelectedIndexChanged

Dim sAircraftID As String = lstAircraftID.SelectedItem.ToString()

txtAircraftID.Text = lstAircraftID.SelectedItem.ToString

This is what I need to happen when I entered the aircraftId and clicked the menu to record the aircraftID the data I placed in the CarrierName textbox should also be recorded, so when I highlight the aircraftID in the listbox along with the aircraftID appearing in it's textbox the CarrierName shold appear in it's textbox.

Can you help me accomplish this??



 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,322
Location
Sydney, Australia
Programming Experience
10+
Try using a sorted list like this:
VB.NET:
Dim carrierNameByAircraftIDList as New SortedList

Private Sub mmuRecordSaveArrival_Click(...) Handles mmuRecordSaveArrival.Click
	Me.lstAircraftID.Items.Add(Me.txtAircraftID.Text.Trim())

	'Add the carrier name to the list indexed by aircraft ID.
	carrierNameByAircraftIDList.Add(Me.txtAircraftID.Text.Trim(), Me.txtCarrierName.Trim())
End Sub

Private Sub lstAircraftID_SelectedIndexChanged(...) Handles lstAircraftID.SelectedIndexChanged
	Me.txtAircraftID.Text = Me.lstAircraftID.SelectedItem

	'Retrieve the carrier name for the selected aircraft ID.
	Me.txtCarrierName.Text = carrierNameByAircraftIDList(Me.lstAircraftID.SelectedItem)
End Sub
 
Top Bottom