简体   繁体   中英

c# dictionary bound to listbox

Hi I have a dictionary which I bind to a bindingsource. I would like to display the keys in a listbox. So i add the bindingsource to the listbox and set the displaymember to "Key". This does not work. It gives me the tostring of the dictionary instead of the key string...

Code used:

        bs_directions.DataSource = bs_measurements;
        bs_directions.DataMember = "zielwertdict"; //(=Dictionary<string,list<object>>)

        listBox3.DataSource = bs_directions;
        listBox3.DisplayMember = "Key";

UPDATE: The bs_measurements is another list which is bound to another listbox. When I build the project the listBox3 displays the keys of the dictionary. When I change the item in the listbox which is bound to bs_measurement then listbox3 displays the dictionary.Tostring() things... very strange...

UPDATE 2: The objects contained in the bs_measurment list have a dictionary (zielwerdict) and a hashtable:

public class bs_measurementOBject
{
public string name;
public SortedDictionary<string,list>object>> zielwertlist;
public Hashtable block;
}

在上面的示例中, bs_directions.DataMember必须为NULL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM