By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,587 Members | 1,070 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,587 IT Pros & Developers. It's quick & easy.

Dictionary Class

P: 18
I have Listbox(lstgroups) and listview(lstItems). say items in lisbox as Groups and in listview as Items.
Each Group should have list of items, when i add an new item to lstitems. it should assign to selected group. and If I add two items to a selected group and moved to Second goup and added items to these. Then if moved to first group the intial added Items are to displayed in Listview. is that Possible.
By using dictionary classes
Here List<object> should return lstitems
Dictionary<string, List<object>> d= new Dictionary(string, List<object>>();
d.add(lstgroups.items, new List<object>);
//error cumes here, how to assign here List<>

Thanks and regards,
Jan 27 '09 #1
Share this Question
Share on Google+
2 Replies

Expert 5K+
P: 7,872
Create the List<object> first and then add it to the dictionary
Jan 27 '09 #2

Expert Mod 5K+
P: 9,731
You need to set the DataSource for the lstItems (your ListView) when you have selected a new item in the lstgroups (your ListBox).

I'm not the greatest with C# so my example is probably not going to work if you copy paste it....but it gives you an idea of what you need to do in order to set the data source of the ListBox.
Expand|Select|Wrap|Line Numbers
  1. Dictionary<string, List<object>> d= new Dictionary(string, List<object>>();
  3. //Create a new List of Objects that will contain the items for the selected group:
  4. List<object> groupItems= new List<object>();
  6. //now you need to populate the "groupItems" (the list of items)  
  7. //with the items for the group.
  8. //You can do this by calling the groupItems.Add() method.
  10. //Once finished populating the groupItems List, add it to your dictionary.
  11. d.add("key", groupItems);
  13. //Set the data source of the ListBox to display the items:
  14. lstgroups.DataSource= d["key"];
  16. //Or you can set it this way:
  17. //lstgroups=groupItems;
Jan 27 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.