1
public static Hashtable m_results = new Hashtable();
private BindingSource m_bindResults = new BindingSource();
// in static constructor
m_results.Add(MyResultTypes.Failed, "Failed");
m_results.Add(MyResultTypes.Pending, "Is Pending");
m_results.Add(MyResultTypes.Completed, "Was Completed");
m_results.Add(MyResultTypes.Cancel, "Cancel it");
m_defaultResult = MyResultTypes.Pending;
// in instance constructor
m_bindResults.DataSource = m_results;
comboResult.DataSource = m_bindResults;
comboResult.ValueMember = "Key";
comboResult.DisplayMember = "Value";
comboResult.SelectedValue = m_defaultTimeoutResult;
以上代碼無法工作:)它使用散列表中的鍵而不是枚舉MyResultTypes使用字符串,並且它正在工作。現在發生的事情是組合框被哈希表的值填充(按我的意思),但默認選定的值沒有被選中。C#:如何通過枚舉綁定HashTable到組合框作爲關鍵?
如何在本例中使用枚舉?感謝
編輯:對不起,ComboTOResult是comboResult,錯過了
編輯2:對不起,它的工作。我的壞
對不起,ComboTOResult是comboResult。在發佈時錯過了它,但仍然不適用於我: - /再看一遍..... – flamey 2010-06-09 15:29:03
你說得對。 Show()中的另一段代碼是字符串的時候。謝謝! – flamey 2010-06-09 15:35:08