473,623 Members | 3,345 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Extending TreeNodes

Question about extending a class. I extended the TreeNode class, like this:

class ExtendedTreeNod e : TreeNode
{
public int value1;
public int value2;
public int NodeLevel()
{ //This function returns the level (depth) of the node
...
}
}

This works all well and fine, except when I do something like the following:

private void Test()
{
int i = 0;
int j = 0;
TreeView MyTreeView = new TreeView();
ExtendedTreeNod e tn = new ExtendedTreeNod e();
tn.Text = "My Node";
tn.value1 = 10;
tn.value2 = 20;
MyTreeView.Node s.Add((Extended TreeNode)tn.Clo ne());
i = ((ExtendedTreeN ode)MyTreeView. Nodes[0]).value1;
j = ((ExtendedTreeN ode)MyTreeView. Nodes[0]).value2;
Console.WriteLi ne(i);
Console.WriteLi ne(j);
}

I get 0, 0. The .Clone() method doesn't clone my extensions to the
ExtendedTreeNod e class and I have to assign values to value1 and value2
after the fact. Is there any way to force .Clone() to clone my extensions
to the TreeNode class?

Thanks in advance,
Michael C.
Nov 16 '05 #1
2 1962
Michael C wrote:
I get 0, 0. The .Clone() method doesn't clone my extensions to the
ExtendedTreeNod e class and I have to assign values to value1 and
value2 after the fact. Is there any way to force .Clone() to clone
my extensions to the TreeNode class?


You need to override the Clone() method to return your ExtendedTreeNod e
and copy your new fields.
Nov 16 '05 #2

"Jack Hanebach" <ja*****@spam.h anebach.net> wrote in message
news:eN******** ******@TK2MSFTN GP11.phx.gbl...
Michael C wrote:

You need to override the Clone() method to return your ExtendedTreeNod e
and copy your new fields.


I knew it was going to be something like that. Can anyone point me to a
tutorial for overriding the Clone() method? If I can figure out how to do
this, it'll greatly simplify my code!

Thanks,
Michael C.
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2413
by: Norbert Heidbüchel | last post by:
Hi all, I have read a lot of postings and web pages about drag and drop and treeviews, but could not find an answer to my problem. Sorry, if I missed something. I am trying to drag and drop treenodes defined by myself and don't understand, how to get the nodes data in the dragdrop event. I'm not very experienced in .NET and for sure there is a simple solution. I've written a short sample program, based on well known examples,
3
2702
by: Kilroy Programmer | last post by:
Is there a way to store a unique numeric identifier (say, for example, an int) into a TreeNode, so that when the TreeNode is checked (since CheckBoxes is enabled) the eventhandler AfterCheck() can examine the responsible Node's identifier to see which TreeNode triggered the event? Analyzing the Node's Text string is undesirable because it would mean performing a string compare to a set of predefined strings. This is slower and not easily...
2
1575
by: Patrick McGuire | last post by:
Article 311318, "HOW TO: Create a Key Property for a TreeView Node in Visual Basic .NET". Explains how to extend the treeview (and treenode) classes to include a node Key. However, to obtain a node reference, you must still either use the index, or use a for each ... next loop in you code to get it by key. I would like to use the node's key or index interchangeably. To do this, I think I need to change the treeview's Nodes property...
5
3823
by: vbgunz | last post by:
Hello everyone. I own two books. Learning Python and Python in a nutshell. When cross referencing the two books to try and clarify the ideas behind extending methods and delegates, this is where confusion veered it's ugly head :( Learning Python explains on page 324: Class Interface Techniques (21.3.3 in the ebook) the following is an extender method. ''' #################################### '''
10
1750
by: DrPete | last post by:
Hi People Could anyone suggest to me the best way to distinguish treenodes? By this I mean I'm in a situation where I have a TreeNode that displays a number of categories and within those nodes there are items of stock. There are a number of things I wish to do, such as use a ContextMenu to Rename the node, but I can't seemingly tell if the Node I'm renaming is a category or an item of stock.
0
1113
by: David | last post by:
Can WebControls be added to TreeNodes in the TreeView? David -- Be Positive Every Day
0
1218
by: SBelzile | last post by:
Hi, We are working on a vb.net WinForms project based on the Composite UI Application Block (VS2005). I have a strange problem. At first, I thought 10 minutes would be fairly enough for me to solve it but I've spent almost 6 hours on it today and still can't figure out what's wrong. Using the CAB, I have built a control that intercepts messages coming from other CAB's SmartParts controls and display them into a treeview control. The...
3
3670
by: katis | last post by:
Hi all :) Is it posible in xsd to change only minOccurs value of element in complex type by extending this type? The problem I'm trying to solve is this: I have two complex types - "TextField" and "FileChooser". Here is definition of "TextField" <xsd:complexType name="TextField">
2
2183
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
My first time using a TreeView: I've got a TreeView that I populated with some data and it has nodes. In the Properties window, I created an Event Handler for the TreeView's AfterSelect method, and it allows me to determine what Tree Node has been selected. However, if I expand the TreeView and select one of the Child TreeNodes, they do not trigger this event.
0
8221
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8162
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8317
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7134
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5560
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4067
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2593
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1468
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.