2014-03-04 168 views
0

我通過LINQ將特定列值加載到列表中,我想要獲取這些值的特定實例。這是我的頁面加載代碼。從Entitiy列表中獲取特定值

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 

在ListBox的selectedIndexChange,我想給item.ContractDealerID值應用到一個文本框。

Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged 

    TextBox1.Text = ListBox1.SelectedValue.????????????? 

End Sub 

回答

1

首先,我會考慮使用數據網格或listview控件。

要回答您的問題:您需要使用SelectedItem屬性。

實施例:

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