我试图将列表绑定到组合框

时间:2013-07-09 13:06:42

标签: wpf vb.net binding combobox

我将有各种列表,我将绑定到各种组合框,所以我创建了一个名为'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

此应用程序中的其他绑定正在运行,因此我怀疑这是我创建此列表然后绑定它的方式。任何帮助/见解将不胜感激。

1 个答案:

答案 0 :(得分:0)

您的路径设置为my_listmyValueList的实例),但您的类的属性名为list,您应该绑定到my_list.list,这是实际的枚举。