Combobox未显示DisplayMember值

时间:2014-04-24 14:57:48

标签: vb.net winforms combobox datasource

我正在尝试使用组合框来显示自定义对象的列表(T)。该对象如下所示:

    Public Class KeyValue(Of K, V)

    Public Sub New()
    End Sub

    Public Sub New(ByVal key As K,
                   ByVal value As V)
        Me.Key = key
        Me.Value = value
    End Sub

    Public Property Key As K
    Public Property Value As V

End Class

我填充这样的组合框:

        Private Sub FillCountries()
        If cboCountry.DataSource Is Nothing Then
            Dim table As DataTable = GetTableByName(GetQualifiedName(Of DataModel.TableModels.Reference.CountryMain), True)
            Dim source As New List(Of KeyValue(Of String, String))
            For Each row As DataRow In table.Rows
                source.Add(New KeyValue(Of String, String)(row.Item("pkCountryCode").ToString,
                                                           row.Item(CountryName).ToString))
            Next
            cboCountry.DisplayMember = "Value"
            cboCountry.ValueMember = "Key"
            cboCountry.DataSource = source
        End If
    End Sub

我首先尝试设置DisplayMember以及ValueMember。无论哪种方式,我得到一个组合框,显示KeyValue.ToString()值而不是Value属性的值。

由于

0 个答案:

没有答案