我將有各種各樣的,我要綁定到各種組合框的列表,所以我創建了一個名爲「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
在此應用程序的其他綁定工作,所以我懷疑這是我要如何創建這個列表,然後結合的方式。任何幫助/見解將不勝感激。
是不是'list'是一個集合的實際屬性?如果是這樣,你的綁定應該不是'ItemsSource =「{Binding Path = my_list.list}」'?你的my_list是類似於擁有列表屬性的類,但看起來像是你的父對象而不是嵌套子對象的綁定。 VB不是我熟悉的東西,所以只是一個瘋狂的猜測,你可能會嘗試 – Viv
@Viv就是這樣!謝謝。 – volderArt