Using selectedIndexChanged

uncle55

Member
Joined
Jun 27, 2004
Messages
5
Location
Wisconsin
Programming Experience
Beginner
I'm a newbie at vb.net that needs some help. I trying to figure out how to display a truck in other control instances when the user selects TruckId in the listbox.

For instance there are three textboxes (txtTruckID,txtCompany,txttypeof)and a listbox (lstTruckID). When the input is put in all three txtboxes and the menu is clicked the truckID appears in the listbox.When there is more then one truckId in the listbox and the user highlights a particular truckID the input that goes with that Truckid should appear in the textboxes.

Is this possible using the SelectIndexChanged event?
 
yes very possible.
try this one.
i'll make a datatable for you to store the value that you input in the textbox.
In the listbox selected index change i'll loop through all the rows of the datatable and check if the id that was selected in the listbox exist in the datatable..if so retrieve the corresponding value.

VB.NET:
Dim dt As New DataTable()
	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		dt.Columns.Clear()
		dt.Columns.Add(New DataColumn("truckID"))
		dt.Columns.Add(New DataColumn("Company"))
		dt.Columns.Add(New DataColumn("Typeof"))
	End Sub

	Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim dr As DataRow = dt.NewRow
		dr(0) = Me.TextBox1.Text
		dr(1) = Me.TextBox2.Text
		dr(2) = Me.TextBox3.Text
		dt.Rows.Add(dr)
		ListBox1.Items.Add(TextBox1.Text)
		Me.cleartextbox()
	End Sub

	Sub cleartextbox()
		TextBox1.Text = ""
		TextBox2.Text = ""
		TextBox3.Text = ""
	End Sub

	Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
		Dim s As Integer = CInt(ListBox1.SelectedItem)
		Dim dr As DataRow
		For Each dr In dt.Rows
			If CInt(dr(0)) = s Then
				Me.cleartextbox()
				TextBox1.Text = dr(1).ToString
				TextBox2.Text = dr(2).ToString
			End If
		Next
	End Sub
 
Back
Top