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,它正在工作。现在发生的是组合框填充了哈希表的值(如我所愿),但未选择默认选定值。

在这个例子中如何使用枚举?谢谢

编辑:对不起,ComboTOResult 是 comboResult,错过了

编辑2:对不起,它确实有效。我的错

4

1 回答 1

2

当我将最后一行更改为时为我工作

comboResult.SelectedValue = m_defaultResult; 

ComboTOResult 可能是一个不同的盒子?

于 2010-06-09T15:17:22.510 回答