[.net] .Net 2005 Inheriting ListView problems

Started by
6 comments, last by Arild Fines 17 years, 11 months ago
Okay, i don't know what's wrong but i destinctly remembered being able to create a custom control that inherited for example ListView. When i try to pick one of the inherited options in add a new item all i get is to inherit it from a dll or a form that's already in the project. How can i create a class that inherits the ListView without having to create the class manually since that's only a work-around. :/ [Edited by - Cybrosys on May 19, 2006 4:51:10 PM]
Advertisement
Ok.. I am not sure I am reading this right so can you clarify. Are you trying to instanciate a custom Listview control that you want to manually set the properties of or are you trying to create a Custom Control Listview Class that is inherited from ListView?

theTroll
What is the proper way of doing it if i want to add functionality to the ListView control?
You should subclass the ListView, that is your class should be
public class Whatever : ListView { ...}
If you want to add functionality then you have to make your own class that inherits from ListView.

class CustomListView : ListView{    public void myCustomFunction()    {        //...    }}


That should do it for you.

theTroll
When i inherit, the class stops being a User control and becomes a Component and i lose the ability to add it to a form from the toolbox.
This will show you how to do it.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnppcgen/html/sp_lab1_build_custom_control.asp

theTroll
Quote:Original post by Cybrosys
When i inherit, the class stops being a User control and becomes a Component and i lose the ability to add it to a form from the toolbox.

But you *can* add Components to a form. For example, the Tooltip class inherits from Component.

That being said, I've always thought the tool box was a bit erratic in what it picked up from your own controls and offered for use. For example, if the project containing your custom control/form is under a solution folder, it won't show up in the tool box at all.

What I usually do when inheriting standard controls is just start out with a UserControl, then changing it in the code to inherit from the control I want.
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]

This topic is closed to new replies.

Advertisement