CollectionBase IBindingList confliction problems

N

Narshe

I have a collection class that inherits from CollectionBase, and
implements IBindingList, and I'm having problems with recursion or List
not having an instance.

This is a simple version of the class.

public class MyCollection : CollectionBase, IBindingList
{
public int Add( object value )
{
return this.List.Add( value );
}
}

This causes an infinite loop when trying to add to the collection, and
I think it's because IBindingList implements IList, so it keeps calling
itself.

So I pass the actual class object type in instead.

public class MyCollection : CollectionBase, IBindingList
{
public int Add( MyClass value )
{
return this.List.Add( value );
}
}

When I do this, List either will give an error about a null reference,
or it will return void and not add anything to the list.

I've seen this done all over the place, but it doesn't seem to be
working for me.

Am I doing this wrong?
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

public class MyCollection : CollectionBase, IBindingList
{
public int Add( object value )
{
return this.List.Add( value );
}
}

I think the correct way is this.InnerList.Add( value)

what is what you expect to return? what that int represent?


cheers,
 
N

Narshe

Manipulating everything via innerlist might stop the IList
implementation conflictions.

I'm actually not going to use IBindingList anymore, so I don't need to
worry about it now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top