Results 1 to 7 of 7

Thread: Enumerating Dictionary Objects

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Enumerating Dictionary Objects

    I am just tring to enumerate my collection class that inherits from DictionaryBase, and i just cant seem to get it working right

    I have a products class containing objects of type product

    when I do

    for each Prod in Prods

    next

    where the default property in Prods is Item which returns an object of type Prod

    it says there is an invalid cast...

    any ideas how I can get this to work?

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    The enumerator for DictionaryBase actually returns DictionaryEntry objects, which contain the key/value pair. What I normally do is put this in my collection class...
    VB Code:
    1. Public Shadows Function GetEnumerator() As IEnumerator
    2.         Return Dictionary.Values.GetEnumerator
    3.     End Function

    And then your code should work.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    using that do I not use for each in the form code then?

  4. #4

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    never mind, got it to work. Thanks.

  5. #5
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    The Netherlands
    Posts
    425

    Re: Enumerating Dictionary Objects

    Hi Kleinma,
    I'm having a similar problem. Can you tell me how you fixed it?
    Thx.
    Last edited by BShadow; Dec 7th, 2006 at 05:05 AM.
    "Experience is something you don't get until just after you need it."

  6. #6

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Enumerating Dictionary Objects

    Hmmm it was 2 years ago, and honestly I can't remember exactly what I did. If you post your code I will try to fix it though.

  7. #7
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    The Netherlands
    Posts
    425

    Re: Enumerating Dictionary Objects

    Thanks kleinma, it's related to here;
    http://www.vbforums.com/showthread.php?t=441737
    "Experience is something you don't get until just after you need it."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width