Dim CountryArr As New ArrayList
Dim CountryName As String() = New String() {"N1","N2","N3"}
Dim CountryCode As String() = New String() {"C1","C2","C3"}
For i As Integer = 0 To UBound(CountryName)
CountryArr.Add(New KeyValuePair(Of String, String)(CountryCode(i), CountryName(i)))
Next
CountryArr.Add(New KeyValuePair(Of String, String)(CountryCode(i), CountryName(i)))
Next
With ComboBox
.DataSource=CountryArr
.DisplayMember = "value"
.ValueMember = "key"
.ValueMember = "key"
End With
取得SelectItem時..
CType(ComboCountry.SelectedItem, KeyValuePair(Of String, String)).Value ==>顯示在畫面上的值
CType(ComboCountry.SelectedItem, KeyValuePair(Of String, String)).Key ==>隱藏的value值
ComboBox1.DataSource = Ds.Tables(0)
ComboBox1.DisplayMember = "charName"
ComboBox1.ValueMember = "charID"
如果DrooDownStyle=DropDownList
ComboBox1.SelectedItem
ComboBox1.SelectedValue
ComboBox1.DisplayMember = "charName"
ComboBox1.ValueMember = "charID"
如果DrooDownStyle=DropDownList
ComboBox1.SelectedItem
ComboBox1.SelectedValue
如果DrooDownStyle=DropDown
ComboBox1.SelectedText
ComboBox1.SelectedValue
ComboBox1.SelectedText
ComboBox1.SelectedValue
沒有留言:
張貼留言