在Combobox中使用Dictionary作为ValueMember

时间:2015-03-11 16:00:01

标签: c# .net winforms combobox

我有一个combobox,我希望在其中显示一个字符串DisplayMemberDictionary<string,string>ValueMember。我有一个列表,其中包含带有字符串和字典的对象,这个列表我用作DataSource的{​​{1}}。

ComboBox

List<myObject> myList = new List<myObject>{ new myObject {myDisplayMember = "TEXT", myValueMember = new Dictionary<string,string> {{"A","ABC"},{"D","DEF"}}} }; myComboBox.DataSource = new BindingSource(myList, null); myComboBox.DisplayMember = "myDisplayMember"; myComboBox.ValueMember = "myValueMember"; 按预期工作,“文字”显示在DisplayMember中,但当我收到ComboBox时,我只收到一串“ValueMember”,而不是我想要的字典。我正在努力,还是有更好的选择?

1 个答案:

答案 0 :(得分:0)

vector < string > splitstring;
boost::split(splitstring, *pos, boost::is_any_of(" "));