Solved

How to derive TreeNodeCollection class

Posted on 2002-07-04
16
1,599 Views
Last Modified: 2010-08-05
Hi,
I am trying to extend the TreeView class in C#. I am not able to derive the TreeNodeCollection class. It seems that its constructor is private.
Is there any way to inherit this class?
0
Comment
Question by:tandrei
  • 8
  • 3
  • 2
  • +2
16 Comments
 
LVL 4

Expert Comment

by:CoolAss
ID: 7130839
Well, TreeNodeCollection is not sealed... but you're correct, it doesn't have any constructor specified.

You don't need a constructor, however, to derive your new class.
0
 
LVL 1

Author Comment

by:tandrei
ID: 7131153
CoolAss,
Please tell me how, cause I get a compile error when I try to derive it because I can't override the constructor.
0
 
LVL 4

Expert Comment

by:CoolAss
ID: 7131280
Paste the code and the error you're getting.
0
 
LVL 1

Author Comment

by:tandrei
ID: 7131807
public class BLTreeNodeCollection: System.Windows.Forms.TreeNodeCollection
{
  public BLTreeNodeCollection()
  {
  }
//...
}
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7131891
Indeed no need to override

public class BLTreeNodeCollection: System.Windows.Forms.TreeNodeCollection
{
 public BLTreeNodeCollection() : base()
 {
    // in here do all YOUR code.
 }
//...
}
0
 
LVL 1

Author Comment

by:tandrei
ID: 7131894
public class BLTreeNodeCollection: System.Windows.Forms.TreeNodeCollection
{
  public BLTreeNodeCollection()
  {
  }
//...
}
0
 
LVL 1

Author Comment

by:tandrei
ID: 7131930
CJ_S,
I derived the class as you sugested, but I get the same error. I put no code in the constructor.


C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\BLTree\Class1.cs(10): No overload for method 'TreeNodeCollection' takes '0' arguments
0
 
LVL 1

Author Comment

by:tandrei
ID: 7131960
CJ_S,
I derived the class as you sugested, but I get the same error. I put no code in the constructor.


C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\BLTree\Class1.cs(10): No overload for method 'TreeNodeCollection' takes '0' arguments
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 1

Author Comment

by:tandrei
ID: 7132017
CJ_S,
I derived the class as you sugested, but I get the same error. I put no code in the constructor.


C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\BLTree\Class1.cs(10): No overload for method 'TreeNodeCollection' takes '0' arguments
0
 
LVL 1

Expert Comment

by:GuryTraub
ID: 7135085
Why not inherit the TreeNode class itself, and use the old known TreeNodeCollection, but with yourTreeNode classes instead of the regular.

I did this in my application recently, and it works fine.
In fact in the same manner you can inherit ListViewItem, etc'..

That's the best way to do it I think..
Gury
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7135193
Or have a public TreeNodeCollection object and you add the functions to the class itself.

I haven't been able to derive from it either.

CJ
0
 
LVL 1

Author Comment

by:tandrei
ID: 7136975
GuryTraub,
I wanted to do this , but how can I add my TreeNode to the system TreeNodeCollection?If my TreeNode extends the system TreeNode and I cast it to the system TreeNode in order to add it to the system TreeNodeCollection class I should lose all my extends!
0
 
LVL 4

Expert Comment

by:DarthPedro
ID: 7149759
You wouldn't lose all of your extensions.  When you get your TreeNode out of the collection, you just need to cast it to your class, and then you can access the new methods/properties that you've added.
0
 
LVL 1

Accepted Solution

by:
GuryTraub earned 70 total points
ID: 7152457
I dont understand what you are saying.
You are wrong, my friend
I did exactly this, in an application I wrote not long ago.
I derived from TreeNode.

and then you can do something like

TreeNodeCollection col;

col.Add(YourDerivedTreeNode node);

and it will work, and you won't lose your extensions..

I probably dont fully understand the problem, so please elaborate..
Gury
0
 
LVL 4

Expert Comment

by:CoolAss
ID: 7153167
GuryTraub,

Please do not propose an answer like that. Use the comment post, then, if the person asking the question feels your comment has helped, he or she will accept it as the answer.
0
 
LVL 1

Author Comment

by:tandrei
ID: 7153531
Thanx GuriTraub, I already did that and it really works OK.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
What is MicroStrategy.NET? 2 47
insert image with its metadata into SQL server Database 3 31
bulid json format 3 21
C# TextBox 11 16
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now