嗨我有一個字典,我綁定到一個綁定源。我想在列表框中顯示這些鍵。所以我將bindingsource添加到列表框並將displaymember設置爲「Key」。這不起作用。它給我的字典,而不是關鍵字符串的toString ...使用c#字典綁定到列表框
代碼:
bs_directions.DataSource = bs_measurements;
bs_directions.DataMember = "zielwertdict"; //(=Dictionary<string,list<object>>)
listBox3.DataSource = bs_directions;
listBox3.DisplayMember = "Key";
UPDATE: 的bs_measurements是被綁定到另一個列表框另一個列表。當我構建項目時,listBox3顯示字典的鍵。當我更改綁定到bs_measurement的列表框中的項目時,listbox3顯示dictionary.Tostring()的東西...非常奇怪...
UPDATE 2: bs_measurment列表中包含的對象有一個字典zielwerdict)和散列表:
public class bs_measurementOBject
{
public string name;
public SortedDictionary<string,list>object>> zielwertlist;
public Hashtable block;
}
您可能需要的數據源設置爲新的BindingSource,即; bs_directions.DataSource = new BindingSource(bs_measurements,null); –
這不會改變任何東西 – benst