Results 1 to 6 of 6

Thread: [02/03] Enumerating a subset of a strongly typed collection

  1. #1

    Thread Starter
    Fanatic Member Mr.No's Avatar
    Join Date
    Sep 2002
    Location
    Mauritius
    Posts
    651

    [02/03] Enumerating a subset of a strongly typed collection

    Hi

    I have a strongly typed collection of Employee objects called EmployeeCollection and the Employee object exposes a property for departmentCode. I need to do some processing on employees belonging to specific departments so I though I'd have a method that would expose a filtered view of the collection. After some digging it looks like I need to implement my own Enumeration class using IEnumerator. Can someone point me to some good code samples on how to achieve this?

    I'm using VS.NET 2003

    Thanks
    Last edited by Mr.No; Oct 20th, 2007 at 11:39 AM. Reason: change title
    Using VB.NET 2003/.NET 1.1/C# 2.0
    http://del.icio.us/rajoo
    Blow your mind, smoke gunpowder
    Ashes to ashes, dust to dust
    If God won't have you, the devil will. - Author unknown
    Don't follow me, I'm lost too ...

  2. #2

    Thread Starter
    Fanatic Member Mr.No's Avatar
    Join Date
    Sep 2002
    Location
    Mauritius
    Posts
    651

    Re: [02/03] Enumerating a subset of a strongly typed collection

    I got a mail alert that jmcilhinney replied to my post but I don't see t here
    Using VB.NET 2003/.NET 1.1/C# 2.0
    http://del.icio.us/rajoo
    Blow your mind, smoke gunpowder
    Ashes to ashes, dust to dust
    If God won't have you, the devil will. - Author unknown
    Don't follow me, I'm lost too ...

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [02/03] Enumerating a subset of a strongly typed collection

    I recommended that you implement the IBindingListView interface in another class, which I have done myself to provide sorting and filtering of a typed Collection. I then realised that you're on .NET 1.1 and that interface is new in .NET 2.0, so I deleted my post.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Fanatic Member Mr.No's Avatar
    Join Date
    Sep 2002
    Location
    Mauritius
    Posts
    651

    Re: [02/03] Enumerating a subset of a strongly typed collection

    jmcilhinney, thanks for taking time to respond to my post.
    Until I find the right way I have added an overloaded GetEnumertor method that takes department code as argument. I then initialise an EmployeeCollection object to which I add the employees who form part of the departmentcode. An the end of the method I return the newEmpCol.GetEnumerator object.
    I don't quite like the idea of building another list, I would have thought of something that would have built and returned a virtual list of indexese that match the department code.

    Thanks
    Using VB.NET 2003/.NET 1.1/C# 2.0
    http://del.icio.us/rajoo
    Blow your mind, smoke gunpowder
    Ashes to ashes, dust to dust
    If God won't have you, the devil will. - Author unknown
    Don't follow me, I'm lost too ...

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [02/03] Enumerating a subset of a strongly typed collection

    Building another list is no big deal because you aren't copying the actual objects, just the references to them. That's no different to returning a list of indices as far as resources are concerned.
    Last edited by jmcilhinney; Oct 21st, 2007 at 07:59 AM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Fanatic Member Mr.No's Avatar
    Join Date
    Sep 2002
    Location
    Mauritius
    Posts
    651

    Re: [02/03] Enumerating a subset of a strongly typed collection

    Thanks, you re-assure me in my design then.
    Using VB.NET 2003/.NET 1.1/C# 2.0
    http://del.icio.us/rajoo
    Blow your mind, smoke gunpowder
    Ashes to ashes, dust to dust
    If God won't have you, the devil will. - Author unknown
    Don't follow me, I'm lost too ...

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