473,796 Members | 2,826 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unique identifier in every treenode?

Is there some sort of unique identifier in every treenode
that is consistent? I was looking at the handle of every
treenode, but it appears that the handle changes everytime
the tree is built.

I have seen in some databases where they store the treenodes
they are using some serial number of the node. I don't have
a clue what that is, but can someone tell me if there is something
that is unique to every node.
Thanks

Rob
Jan 3 '08 #1
4 4265
Rob,

Well, within the confines of the program itself, then the reference
itself is unique, and you should be able to compare object references.

If you are talking about something you can persist, then you need to
look at other options. You need to associate that identifier with the node.

If the full path consisting of the label names represent a unique
identifier, then you can use the FullPath property on the TreeNode instance
to get the path from the root to that node. If not, then you will have to
assign something to the Tag property, creating the identifier and restoring
it when you recreate the tree from whatever underlying storage you are
using.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Rob Stevens" <ro**********@s undry.comwrote in message
news:eH******** ******@TK2MSFTN GP06.phx.gbl...
Is there some sort of unique identifier in every treenode
that is consistent? I was looking at the handle of every
treenode, but it appears that the handle changes everytime
the tree is built.

I have seen in some databases where they store the treenodes
they are using some serial number of the node. I don't have
a clue what that is, but can someone tell me if there is something
that is unique to every node.
Thanks

Rob


Jan 3 '08 #2
Thanks Nicholas,

I ask this question because I have been looking at a lot of example code
within the
last week. And it's really confusing the way the tree is being stored to
whatever
storage is being used, and restored with the same exact layout still remains
a
mystery to me. I see no where in anyone's code where they are storing node
names,
levels, nothing. Here is an example I found last night, but even after
debugging and
looking at the values, I still can't see anything at all that shows me the
exact layout of
a tree.

void SaveTreeView(Tr eeView tree, string filename)
{
ArrayList al = new ArrayList();
foreach (TreeNode tn in tree.Nodes)
{
al.Add(node);
//listBox.Items.A dd(node.Text + "," + depth);
}

Stream file = File.Open(filen ame, FileMode.Create );
BinaryFormatter bf = new BinaryFormatter ();
try
{
bf.Serialize(fi le, al);
}
catch (System.Runtime .Serialization. SerializationEx ception e)
{
MessageBox.Show ("Serializat ion failed : {0}", e.Message);
}
file.Close();
}

void LoadTreeView(Tr eeView tree, string filename)
{
if (File.Exists(fi lename))
{
Stream file = File.Open(filen ame, FileMode.Open);
BinaryFormatter bf = new BinaryFormatter ();
object obj = null;
try
{
obj = bf.Deserialize( file);
}
catch (System.Runtime .Serialization. SerializationEx ception
e)
{
MessageBox.Show ("De-Serialization failed : {0}",
e.Message);
}
file.Close();

ArrayList nodeList = obj as ArrayList;

// load Root-Nodes
foreach (TreeNode node in nodeList)
{
tree.Nodes.Add( node);
//listBox.Items.A dd(node.Text);
}
}
}

I think until I figure out a lot of these underlying things in the code, I
will never understand what
I am looking at. I can't see individual properties being saved, its just a
mystery.

Rob
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c omwrote in
message news:uI******** *****@TK2MSFTNG P04.phx.gbl...
Rob,

If you are talking about something you can persist, then you need to
look at other options. You need to associate that identifier with the
node.

Jan 3 '08 #3
On Thu, 03 Jan 2008 12:04:29 -0800, Rob Stevens <ro**********@s undry.com>
wrote:
I ask this question because I have been looking at a lot of example code
within the
last week. And it's really confusing the way the tree is being stored
to whatever
storage is being used, and restored with the same exact layout still
remains a
mystery to me. I see no where in anyone's code where they are storing
node names,
levels, nothing. Here is an example I found last night, but even after
debugging and
looking at the values, I still can't see anything at all that shows me
the
exact layout of a tree.
That's because all the important stuff is hidden in the serialization code
for TreeNode.

I'm not really all that familiar with the specifics myself, but the code
you posted simply enumerates the root nodes, serializing each one. Then
in the "Load" method, it deserializes the stored data into an array of
TreeNodes, representing the root nodes, and adds each root node to the
tree.

Since TreeNode implements ISerializable and assuming the code you posted
works, it must include logic for serializing the entire structure under a
given TreeNode. To see specifically how it works, you would have to look
at the implementation for TreeNode itself, and/or the output from the
serializer (but you'd probably want to use a different formatter than
BinaryFormatter , so that you get something that's reasonable
human-readable). But there's nothing magical about it...it just means
that the code you posted is relying on an existing implementation that
already handles the job of relating the nodes somehow.

You could either take advantage of that, or write your own
implementation. Depending on your needs with respect to persisting the
data, either approach could be warranted.

Pete
Jan 3 '08 #4
Thanks Pete,

You have given me a lot of great ideas, now I have to put them to use.

Thanks again.

Rob
Jan 3 '08 #5

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

Similar topics

4
15656
by: Louis Frolio | last post by:
Greetings All, I have read many upon many articles here regarding GUID data types and uniqueness. There have been many opinions regarding the effectiveness of GUID's and when they should/should not be used. However, every article strongly implies, if it does not state it outright, that GUID's are always unique. My question is this, what happens if you have a database that uses GUID's and the NIC is changed out on the box? From what I...
3
2710
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...
6
3063
by: Mullin Yu | last post by:
hi, i have a web service that has file operations on Windows OS, and there may be a file concurrency issue if only one working directory e.g. c:\working therefore, i want to have a unique sub directory for each request so as to get rid of any file concurrency issue, e.g c:\working\unique-identifier1 for Request #1 c:\working\unique-identifier1 for Request #2
4
10123
by: ba.hons | last post by:
Hello all, Was wondering if anyone could provide some info on what could be a possible solution to a problem am having. I have to generate a Unique Identifier in C# which I will use to assign to a user, i dont really need the Unique Identifier's to be sequential so i was considering using system.time.hour + system.time.minute. + system.time.second, but am worried about daylight savings and also people altering the time on the host PC.
2
6210
by: Ken | last post by:
Hi, I have a form whose control source is a view from SQL server 2005 database. The view has a primary key that is a unique identifier field with keys generated by newid() function from SQL server 2005. Anyhow when I try to view/assign the unique identifier field and debug/ use watchlist I get this "????????" for the value of the unique identifier. I am able to create a text box with this unique identifier field and view it. Its just when...
8
2075
by: DaTurk | last post by:
Hi, I was just curious how you would go about creating a unique identifier with 3 ints.
14
7543
by: Steven D'Aprano | last post by:
I have an application that will be producing many instances, using them for a while, then tossing them away, and I want each one to have a unique identifier that won't be re-used for the lifetime of the Python session. I can't use the id() of the object, because that is only guaranteed to be unique during the lifetime of the object. For my application, it doesn't matter if the ids are predictable, so I could do something as simple as...
4
2372
by: Mufasa | last post by:
I'm looking for a way to get a truly unique identifier for a machine for our client software. I'd like to have it so that there's little or no setup by the end user. (We set up the machines and then ship them out for most cases but some of our customers do provide their own machines.) Our concern is if somebody takes one of our machines and ghosts it so they have a complete copy of the machine, it will allow them to continue working. We...
13
3715
by: mliptak | last post by:
I'm trying to implement logging in my application, so that each log message has its unique identifier, e.g. log(identifier, text) What I want to achieve is that the compiler screams if the log() with 'identifier' is also used in some other place in the code which would make the 'identifier' not unique. Is that something that can be achieved in C++? Thanks
0
9673
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
10452
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10221
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6785
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
5440
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
5569
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
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.