tags:

views:

110

answers:

2

I'm trying to create a class that inherits from ListViewItemCollection, and I got this error: "No overload for method 'ListViewItemCollection' takes '0' arguments".

Any idea how to fix it or how I can inherit from this class. All suggestions are welcome. Greetings!

+1  A: 

It seems that the ListViewItemCollection class does not have a public default constructor.

This means that you will have to explicitly create a constructor in your class, which calls one of the accessible (protected or public) constructors in the ListViewItemCollection class.

The ListViewItemCollection class does have a public constructor which takes a ListView as an argument.

So, your class could look like this:

public class MyListViewItemCollection : ListView.ListViewItemCollection
{
     public MyListViewItemCollection ( ListView owner ) : base(owner)
     {}
}

edit: The constructor which takes a ListView as an argument, is the only constructor that is accessible, so you'll have to do it like my example above.

Frederik Gheysels
The ListViewItemCollection is declared inside the ListView type, so you will need to include that in the declaration: "ListView.ListViewItemCollection" instead of "ListViewItemCollection".
Fredrik Mörk
+3  A: 

Frederik's answer is correct, ListViewItemCollection class needs an owner i.e. a ListView object to be passed in to the constructor.

However, I think his declaration is wrong, you may need to do:

public class MyListViewItemCollection : ListView.ListViewItemCollection
{
    public MyListViewItemCollection(ListView owner)
        : base(owner)
    {
    }
}
James
Indeed; ListViewItemCollection is declared inside the ListView class.My code however, was written directly in the SO editor, so I haven't verified it with the compiler or whatsoever.Anyway, I've adapted it. :)
Frederik Gheysels
Thanks for the help it works fine =)
doc