Hey, I've got a little problem with displaying my Dictionary in ListBox.
public static Dictionary<String, List<String>> MyDict = new Dictionary<string,
List<String>>();
...
if(MyDict[value1] == null){
List<String> Temp_List = new List<String>();
Temp_List.Items.Add(sth);
MyDict[value1] = Temp_List;
}
else if(MyDict[value1].Count < 4){
...
List<String> Temp_List = new List<String>();
Temp_List = MyDict[value1];
Temp_List.Add(sth);
MyDict[value1] = Temp_List;
}
and I'd like to display in Page_Load (after logging) a ListBox which will have List from MyDict for this login. Eg. Login is : sally And list contains of: she, no, then And开发者_开发问答 after sally logging I'd like to see result like this:
she
no
then
and I cannot use BindingSource... any ideas?
Example of dictionary binding:-
Dictionary myDictionary = new Dictionary
myDictionary.Add(1, "test");
myDictionary.Add(2, "test2");
value =1 text to display = "test" etc etc
dropdown bind:-
list1.DataSource = myDictionary;
list1.DataValueField = "Key";
list1.DataTextField = "Value";
list1.DataBind();
Hope this helps
Why not use a ListView?
private void PopulateListView(Dictionary<string, string> items, ListView lv)
{
lv.Items.Clear();
foreach (KeyValuePair<string, string> kvp in items)
{
ListViewItem lvi = new ListViewItem(kvp.Value);
lvi.SubItems.Add(kvp.Key);
lv.Items.Add(lvi);
}
}
精彩评论