Dictionary Class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • uday1302
    New Member
    • Mar 2008
    • 18

    Dictionary Class

    Hi,
    I have Listbox(lstgrou ps) and listview(lstIte ms). 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<stri ng, List<object>> d= new Dictionary(stri ng, List<object>>() ;
    d.add(lstgroups .items, new List<object>);
    //error cumes here, how to assign here List<>

    Thanks and regards,
    Uday
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Create the List<object> first and then add it to the dictionary

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      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.
      Code:
      Dictionary<string, List<object>> d= new Dictionary(string, List<object>>();
      
      //Create a new List of Objects that will contain the items for the selected group:
      List<object> groupItems= new List<object>();
      
      //now you need to populate the "groupItems" (the list of items)  
      //with the items for the group.
      //You can do this by calling the groupItems.Add() method.
      
      //Once finished populating the groupItems List, add it to your dictionary.
      d.add("key", groupItems);
      
      //Set the data source of the ListBox to display the items:
      lstgroups.DataSource= d["key"];
      
      //Or you can set it this way:
      //lstgroups=groupItems;

      Comment

      Working...