从组合框中获取键和值,其中项目从哈希表绑定
get key and value from comboBox where item bind from hashtable
我有一个组合框..
ComboBox searchKeyComboBox = new ComboBox() { Left = 100, Top = 22, Width = 230, DropDownStyle = ComboBoxStyle.DropDownList, DataSource = null };
我像这样从哈希表中填充它..
Hashtable fieldTable = new Hashtable();
fieldTable.Add("kore", "Kode");
fieldTable.Add("keerere", "Keterangan");
BindingSource bs = new BindingSource();
bs.DataSource = fieldTable;
searchKeyComboBox.DataSource = bs;
searchKeyComboBox.DisplayMember = "Value";
现在组合框 "searchKeyComboBox" 已经填充了项目的 "Kode" 和 "Keterangan"...
我怎样才能从该组合框中获取该键和值?
由于哈希表本身可以看作是DictionaryEntry
个元素的集合,所以组合框的SelectedItem
将是一个DictionaryEntry,可以从中获取键和值:
var de = (DictionaryEntry)searchKeyComboBox.SelectedItem;
var key = de.Key;
var value = de.Value;
我有一个组合框..
ComboBox searchKeyComboBox = new ComboBox() { Left = 100, Top = 22, Width = 230, DropDownStyle = ComboBoxStyle.DropDownList, DataSource = null };
我像这样从哈希表中填充它..
Hashtable fieldTable = new Hashtable();
fieldTable.Add("kore", "Kode");
fieldTable.Add("keerere", "Keterangan");
BindingSource bs = new BindingSource();
bs.DataSource = fieldTable;
searchKeyComboBox.DataSource = bs;
searchKeyComboBox.DisplayMember = "Value";
现在组合框 "searchKeyComboBox" 已经填充了项目的 "Kode" 和 "Keterangan"...
我怎样才能从该组合框中获取该键和值?
由于哈希表本身可以看作是DictionaryEntry
个元素的集合,所以组合框的SelectedItem
将是一个DictionaryEntry,可以从中获取键和值:
var de = (DictionaryEntry)searchKeyComboBox.SelectedItem;
var key = de.Key;
var value = de.Value;