我将拥有各种列表,并将它们绑定到各种组合框,因此我创建了一个名为“myValueList”的类
Imports MySql.Data.MySqlClient
Public Class myValueList
Public Property list As New List(Of myValueItem)
Public Class myValueItem
Public Property displayString As String
Public Property valueString As String
End Class
Public Sub fill(ByVal mySqlString As String)
Dim myconn As New myLib.mySQL
myconn.setConnectionString("aUser", "aPassword", "aServer", "aDatabase")
myconn.open()
Dim myReader As MySqlDataReader = myconn.sendquery(mySqlString)
Do While myReader.Read
list.Add(New myValueItem() With {.displayString = myReader(0), .valueString = myReader(1)})
Loop
myconn.closeDispose()
End Sub
End Class
然后我试图将它绑定到组合框:
<ComboBox Height="22" Name="ComboBox54" Width="120" HorizontalAlignment="Left" ItemsSource="{Binding Path=my_list}" DisplayMemberPath="displayString" SelectedValuePath="valueString"/>
这是我的主窗口类:
Class MainWindow
Private Sub Window_Loaded(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
Dim myI As New initial
Me.DataContext = myI
End Sub
End Class
这是我的第一堂课:
Public Class initial
Public Property my_list As New myValueList
Public Sub New()
my_list.fill("SELECT * from aTable")
End Sub
End Class
此应用程序中的其他绑定正在工作,所以我怀疑这是我要创建此列表然后绑定它的方式。任何帮助/见解将不胜感激。