0

我有一个字典,我正在尝试用它填充一个 ComboBox。我的 Settings 类有一个名为 Symbol 的字符串属性,这是我想要在下拉列表中显示的内容,并且我希望 comboBox.SelectedItem 成为一个 Settings 对象。到目前为止,我已经尝试过:

comboBox.DataSource = dictionary.Values.ToList();
comboBox.DisplayMember = "Symbol";
comboBox.ValueMember = null;

BindingSource bindingSource = new BindingSource();
bindingSource.DataSource = dictionary.Values.ToList();
comboBox.DataSource = bindingSource;
comboBox.DisplayMember = "Symbol";
comboBox.ValueMember = null;

我不需要为我正在做的事情绑定数据,我很乐意在构造函数中添加一次所有内容,但是使用 DataSource 而不是循环遍历 dictionary.Values 似乎更干净。预先感谢您的帮助。

4

0 回答 0