首先定义自己需要的类
只要实现了 tostring方法就可以了
Public Class DropListItem Public Sub New(ByVal StrText As String, ByVal StrValue As String)
_Text = StrText
_Value = StrValue
End Sub
Private _Text As String
Public Property Text() As String
Get
Return _Text
End Get
Set(ByVal StrValue As String)
_Text = StrValue
End Set
End Property Private _Value As String
Public Property Value() As String
Get
Return _Value
End Get
Set(ByVal StrValue As String)
_Value = StrValue
End Set
End Property
Public Overrides Function Tostring() As String
Return _Text
End Function
End Class
只要实现了 tostring方法就可以了
Public Class DropListItem Public Sub New(ByVal StrText As String, ByVal StrValue As String)
_Text = StrText
_Value = StrValue
End Sub
Private _Text As String
Public Property Text() As String
Get
Return _Text
End Get
Set(ByVal StrValue As String)
_Text = StrValue
End Set
End Property Private _Value As String
Public Property Value() As String
Get
Return _Value
End Get
Set(ByVal StrValue As String)
_Value = StrValue
End Set
End Property
Public Overrides Function Tostring() As String
Return _Text
End Function
End Class
Me.ComboBox1.Items.Add(New DropListItem("11", "1"))
Me.ComboBox1.Items.Add(New DropListItem("22", "2"))
Me.ComboBox1.Items.Add(New DropListItem("33", "3"))
Me.ComboBox1.Items.Add(New DropListItem("44", "4"))
Me.ComboBox1.Items.Add(New DropListItem("55", "5"))
Dim Item As DropListItem = ComboBox1.SelectedItem '强制转化
MsgBox(Item.Text) End Sub使用项目
指定DataSource就行了。
cboMode.DataSource = oModel.Tables[0];
cboMode.DisplayMember = "RULE_NAME_CH";
cboMode.ValueMember = "RULE_ID";
其它的用法和WEBFORM裡面一樣的!