最近一个很偶然的机会,知道了还有这样一个类,可以专门用来向列表控件添加列表项,这个类就是 DictionaryEntry ,关于这个类的使用方法及其相关介绍,你可以在你的MSDN中找到,如果您没有安装MSDN,请点击这里
Do
While
Reader.Read
ComboBox1.Items.Add( New DictionaryEntry(Reader.Item( " 显示字段 " ), Reader.Item( " 值字段 " )))
Loop
ComboBox1.DisplayMember = " Key "
ComboBox1.ValueMember = " Value "
ComboBox1.Items.Add( New DictionaryEntry(Reader.Item( " 显示字段 " ), Reader.Item( " 值字段 " )))
Loop
ComboBox1.DisplayMember = " Key "
ComboBox1.ValueMember = " Value "
在使用DictionaryEntry对象向列表控件添加数据后, 如果要得到被选定项的“显示的文本”或“项的值”,那么,请使用如下的写法,
Dim
strValue
As
String
=
CType
(ComboBox1.SelectedItem, DictionaryEntry).Value
Dim strKey As String = CType (ComboBox1.SelectedItem, DictionaryEntry).Key
Dim strKey As String = CType (ComboBox1.SelectedItem, DictionaryEntry).Key