Reputation: 291
I load specific column values to a list through LINQ and i would like to grab specific instances of those. Here is the code for my page load.
Public Sub CheckRO_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim dc As New DataWorldDataContext.DataWorldDataContext
Dim nonMatchingDealerID As New List(Of DataWorldDataContext.seanRFMatchTest)
nonMatchingDealerID = (From z In dc.seanRFMatchTests Select z).ToList
For Each item In nonMatchingDealerID
ListBox1.Items.Add(item.ContractDealerID & " " & item.ServiceDealerID & " " & item.intRepairFacilCode & " " & item.chrPgmCode & " " & item.chrRONum & " " & item.chvFacilityName)
Next
End Sub
On selectedIndexChange of the ListBox, i would like to apply the item.ContractDealerID value to a textbox.
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
TextBox1.Text = ListBox1.SelectedValue.?????????????
End Sub
Upvotes: 0
Views: 47
Reputation: 181
First, I would consider using a data grid or listview control.
To answer your question: You need to use the SelectedItem property.
Example:
Dim _SelectedValue As String = ListBox1.SelectedItem.ToString
If Not String.IsNullOrWhiteSpace(_SelectedValue) Then
TextBox1.Text = _SelectedValue.Substring(0, _SelectedValue.IndexOf(" "))
Else
TextBox1.Text = String.Empty
End If
Upvotes: 1