×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Implementing GetEnumerator

Implementing GetEnumerator

Implementing GetEnumerator

(OP)
Hello All,

I have a Custom Class that is bound to several DataGridView controls elsewhere in my forms and is defined as follows:

CODE

namespace Collections.MyCollections
{
    [DataObject]
    public class clsGenericList : BindingList<clsGeneric>
    {
        public clsGenericList()
        {
        }

        //....other methods here

        public IEnumerator<clsGeneric> GetEnumerator()
        {
            return this.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.GetEnumerator();
        }
    }
}

But this code barfs on the GetEnumerator method.  Does anyone know how to implement GetEnumerator for this type of class definition ?

Thanks !

Chew

10% of your life is what happens to you.  90% of your life is how you deal with it.

RE: Implementing GetEnumerator

(OP)
Thanks, Jason !

When I removed the methods for iterating over a collection, then it complained.  It was probably b/c I was returning "this.GetEnumerator();" instead of "base.GetEnumerator();", as you pointed out.

In any event, I redefined clsGeneric to look like this:

CODE

    public class clsGenericList<T> : ICollection<T>
    {
        private int m_count = 0;
        private BindingList<T> ThisList = null;
        public clsGenericList()
        {
            ThisList = new BindingList<T>();
        }

        // Implementing ICollections methods here

        public IEnumerator<T> GetEnumerator()
        {
            return ThisList.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return ThisList.GetEnumerator();
        }
    }

And now all my collection classes inherit from this generic class:

CODE

    public class clsRegistrations : clsGenericList<clsRegistration>
    {
        #region Variables & Properties
        private int m_count = 0;
        private bool m_readonly = false;
        
        // Some custom methods here
    }

And all is hunky-dory again.

Thanks !

Chew

10% of your life is what happens to you.  90% of your life is how you deal with it.

RE: Implementing GetEnumerator

(OP)
....although it does seem to perform poorly (slow).

C.

10% of your life is what happens to you.  90% of your life is how you deal with it.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close