0

在缺少Value属性的情况下,我计划使用类来存储我的物品Text并使用属性。到目前为止,我已经成功了。ValueComboBox

这是我的课:

Public Class clCombobox
Public cname As String
Public cvalue As Integer

    Public Property Display() As String
    Get
        Return Me.cname
    End Get
    Set(ByVal value As String)
        Me.cname = value
    End Set
End Property
Public Property Value() As String
    Get
        Return Me.cvalue
    End Get
    Set(ByVal value As String)
        Me.cvalue = value
    End Set
End Property


Public Sub New(ByVal name As String, ByVal value As String)
    cname = name
    cvalue = value
End Sub

Public Overrides Function ToString() As String
    Return cname
End Function
End Class

数据被添加到ComboBox这样的:

cmbComboxBox.Items.Add(New clCombobox("Text", 1))

到目前为止,这似乎有效。但是我如何取回数据。就像我想要所选CheckBox项目的价值一样?

我尝试使用:

CType(cmbCombobox.SelectedItem, clCombobox).Value()

不工作。

4

1 回答 1

1

根据文档,使用SelectedItem 属性检索您存储在其中的对象。

检索您想要的值的代码:

Dim selectedItem as clCombobox = CType(cmbComboBox.SelectedItem, clCombobox)
Dim value As Integer = selectedItem.cvalue
于 2012-05-06T18:41:26.360 回答