Extend / customise .Net c# treeview control

canuckconsulting
canuckconsulting used Ask the Experts™
on
I am working with a Windows Forms c# aplication using Visual Studio 2010 and .Net 4.  I currenlty have a TreeView control on multiple forms I use to present a list of custom ProductCategories.  In these forms I have methods to populate the TreeView as required.  Instead I would like a custom TreeView control normal in all respects but which would a list of these ProductCategories in the constructor and display it properly.  How can I do this?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
I was hoping to just inherit from the standard control and just add a new constructor to it. I'm just not sure how to do it!
Top Expert 2015
Commented:
Inheritance is effectively the best way. Here is the syntax:

class ProductCategTreeView : System.Windows.Forms.TreeView
{
    public ProductCategTreeView()      
   {
       // Do your stuff
   }
}

Compile once and you will see your new TreeView in a new tab at the top of the Toolbox. Use as you please.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial