473,503 Members | 1,677 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Stack overflow with TreeNode property

Hi Guys,
I am doing some work with a treenode and I want to record the
selected item, and it may change while the user is performing some
tasks and I need to know which one was originally selected.
I want to create a property which will store the selected
TreeNode, and I can refer back to that when it is time to make the
changes. However I get a stack overflow error when I assign to the
propery. Here's the code

private TreeNode OperationNode
{
get
{
return OperationNode;
}
set
{
OperationNode = value;
}
}

I try to assign using OperationNode = TreeView.SelectedNode, and the
stack overflows. Any idea would be appreciated. I have used properties
with strings and int's no problem before but this is the first time I
am using them with a complex type. I'm not sure if I have to create a
new object somewhere, I was playing with Clone, but that creates a
different object to the one i want. I supposed I could clone and then
go through the tree and use the object.Equals function, but there must
be an easier way than that.....

Cheers,

JD
Nov 16 '05 #1
2 1962
The Kiddie wrote:
[...]
private TreeNode OperationNode
{
get
{
return OperationNode;
}
set
{
OperationNode = value;
}
}

I try to assign using OperationNode = TreeView.SelectedNode, and the
stack overflows.

[...]

You need to use an actual variable within your get { } and your set { },
instead of OperationNode. What you're doing here is using the same
property from within the property.

--
Tim Robinson (MVP, Windows SDK)
http://mobius.sourceforge.net/
Nov 16 '05 #2
small typo

it should be:

private TreeNode operationNode = null;

private TreeNode OperationNode
{
get {return operationNode;}
set {operationNode = value;}
}

using OperationNode will just call the property which will cause a stack overflow.

Bill
Hello The,
Hi Guys,
I am doing some work with a treenode and I want to record the
selected item, and it may change while the user is performing some
tasks and I need to know which one was originally selected.
I want to create a property which will store the selected
TreeNode, and I can refer back to that when it is time to make the
changes. However I get a stack overflow error when I assign to the
propery. Here's the code

private TreeNode OperationNode
{
get
{
return OperationNode;
}
set
{
OperationNode = value;
}
}
I try to assign using OperationNode = TreeView.SelectedNode, and the
stack overflows. Any idea would be appreciated. I have used properties
with strings and int's no problem before but this is the first time I
am using them with a complex type. I'm not sure if I have to create a
new object somewhere, I was playing with Clone, but that creates a
different object to the one i want. I supposed I could clone and then
go through the tree and use the object.Equals function, but there must
be an easier way than that.....

Cheers,

JD


Nov 16 '05 #3

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

Similar topics

13
2055
by: Will Pittenger | last post by:
I have a Control derived class. When the parent of the control changes the control's Location property, the stack overflows. I have not found a way to find out what was on the stack when it does...
2
7833
by: David N. | last post by:
My small C# application, running on a Windows 2003 server machine with 512 RAM and 80 gigabytes of diskspace, always bombs out with the following error: >> Fatal stack overfollow error. ...
7
18578
by: Gorge Bush | last post by:
Hi there, all was going well with my first C# project until now as I am getting a Stack Overflow exception. I haven't seen one of those since DOS programming days and back then all you did was up...
5
2497
by: jbix | last post by:
We have a stack overflow happening. We are NOT doing any recusion. We do have an object being created in Global that is being handed the Context (which I assume is specific to the request thread). ...
5
4025
by: moondaddy | last post by:
I'm trying to serialize some xaml elements using the XamlWriter and I'm getting a stack overflow error because the elements have some public properties which get called about a million ( a lot)...
0
7202
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,...
0
7084
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...
0
7278
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6991
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...
1
5013
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
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...
0
3167
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...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.