i。我在XAML页中利用了一个ListBox(称为“ MyList”)。此列表框从启用了Silverlight的WCF服务中成功显示了多个值(通过LINQ to SQL类从SQL Server数据库中获取其数据)。
ii。我需要捕获从ListBox中选择的多个值并处理数据。
iii。目前,即使我选择了多个值,一个简单的TextBox也仅显示ListBox中的一个值。
iv。如果我遍历SelectedItems,则TextBox仅显示服务参考中使用的记录类的名称。
v。我需要的只是所有选定项目的文本。
vi。任何帮助将不胜感激。
Public Class EDRObjectListCBox
Public SubstationCBox As String
End Class
<OperationContract()>
Public Function GetEDRObjectSubstation() As List(Of EDRObjectListCBox)
Dim pDatabase As New UniformanceMDEDailyDataClassesDataContext()
Dim EDRObjectList = _
(From EDRObject _
In pDatabase.EDRObjectLists _
Order By EDRObject.SubstationCBox
Select EDRObject.SubstationCBox Distinct)
Dim pEDRSubstationCBox As New List(Of EDRObjectListCBox)
For Each c In EDRObjectList
pEDRSubstationCBox.Add( _
New EDRObjectListCBox With _
{.SubstationCBox = c.ToString})
Next
Return pEDRSubstationCBox.ToList()
End Function
Partial Public Class MainPage
Inherits UserControl
Private WithEvents pEDRObjectService As New EDRObjectServiceReference.EDRObjectServiceClient()
Private Sub pEDRObjectService_GetEDRObjectSubstation(sender As Object, e As
EDRObjectServiceReference.GetEDRObjectSubstationCompletedEventArgs)
Handles pEDRObjectService.GetEDRObjectSubstationCompleted
MyList.ItemsSource = e.Result.ToList()
MyList.DisplayMemberPath = "SubstationCBox"
MyList.SelectedValuePath = "SubstationCBox"
End Sub
<ListBox x:Name="MyList" SelectionMode="Multiple" ScrollViewer.VerticalScrollBarVisibility="Visible" HorizontalAlignment="Left" Height="140" Margin="174,221,0,0" VerticalAlignment="Top" Width="194"/>
我可以在列表框中选择多个项目
在这里,我选择了2EE-DS-01、2GG-DS-01和2H4-SP-01。
2EE-DS-01
2GG-DS-01
2H1-SS-02
2H4-SP-01
2H4-SP-02
Private Sub ButtonDisplay_Click(sender As Object, e As RoutedEventArgs) Handles ButtonDisplay.Click
For Each i As Object In MyList.SelectedItems
MyTextBox.Text += i.ToString() & ControlChars.NewLine
Next
'Also Tried this, but it only displays the first selected item, three times (2EE-DS-01 2EE-DS-01 2EE-DS-01):
For Each i In ListBoxBreaker.SelectedItems
MyTextBox.Text += ListBoxBreaker.SelectedValue().ToString()
End Sub
2EE-DS-01、2GG-DS-01、2H4-SP-01
UniformanceMDEDaily.EDRObjectServiceReference.EDRObjectListCBox
由于某种原因,它显示记录类的名称?