Dicitionary Geneic Class

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

    Dicitionary Geneic Class

    Hi All,
    Can anyone help me out regarding Dicitonary Generic Class using c#.

    Like I have 3 btns(add, edit and delete), text box , LisBox, Listview. If i add an item from Text it should be added to lIstbox and i have items in listview. They should be assigned to listbox selected item. these can be done through dicitonary classes. If i add new one Listbox item and new listview items are to be added to that selected item.
  • mldisibio
    Recognized Expert New Member
    • Sep 2008
    • 191

    #2
    The ListBox displays a ListBox.ObjectC ollection, which is simply a collection of objects.
    The ListView contains a ListViewItemCol lection which is a collection of ListViewItems.
    A Dictionary has a collection of KeyValuePairs.

    If you want the ListBox to somehow reflect the combination of the TextBox value and the ListView item, you might consider making the each ListBox item a KeyValuePair<st ring, ListViewItem>.

    Comment

    • uday1302
      New Member
      • Mar 2008
      • 18

      #3
      Dictionary classes

      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.
      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<>

      Comment

      • vekipeki
        Recognized Expert New Member
        • Nov 2007
        • 229

        #4
        Here is an example of using Dictionary<>: System.Collecti ons.Generic.Dic tionary.

        Try to explain what is the goal you are trying to accomplish, maybe you don't need a dictionary?

        If you want to assing a list of items to a "group", the easiest way would be to create that list first, and then add it to the dictionary:

        Code:
        // create a list
        List<Object> someItems = new List<Object>;
        
        // add some items
        someItems.AddRange( /* add the items */);
        
        // add these items with a specified key ("group name")
        d.Add(groupName, someItems);
        Note also:
        1. you have to do this for each group
        2. you cannot add the same groupName twice (it will raise an exception)

        Comment

        • mldisibio
          Recognized Expert New Member
          • Sep 2008
          • 191

          #5
          Small syntax note:
          Code:
          List<Object> someItems = new List<Object>();

          Comment

          Working...