473,322 Members | 1,522 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Unique, persistent numeric identifiers for TreeNodes?

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 maintained as the number of TreeNodes
increases.

Using GetHashCode() is undesirable because the resulting hash seems to
depend on the order in which the Nodes are checked.

I am hoping that after declaring a number of unique const ints in the
class constructor, I can later give each TreeNode its own unique
identifier as the TreeView is built. (Again, for easy lookup when
AfterCheck() is triggered). I need the solution to be persistent
across different instances of the program.

Does anyone have ideas on how to do this, or a different way to go
about what I'm trying to achieve? I've only been using C# for about a
week.
Nov 16 '05 #1
3 2689
Kilroy,

If you need persistent unique identifiers to be used across different
instances of the program, then I would go with Guids. I know they are not
numeric, but they are unique, and they persist fine. I assume you are
performing some sort of lookup in a hashtable, so these would work fine as
keys, and you can be sure that they are always unique, everywhere.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Kilroy Programmer" <ki***************@yahoo.com> wrote in message
news:11**************************@posting.google.c om...
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 maintained as the number of TreeNodes
increases.

Using GetHashCode() is undesirable because the resulting hash seems to
depend on the order in which the Nodes are checked.

I am hoping that after declaring a number of unique const ints in the
class constructor, I can later give each TreeNode its own unique
identifier as the TreeView is built. (Again, for easy lookup when
AfterCheck() is triggered). I need the solution to be persistent
across different instances of the program.

Does anyone have ideas on how to do this, or a different way to go
about what I'm trying to achieve? I've only been using C# for about a
week.

Nov 16 '05 #2
I will answer my own question. In retrospect it's obvious that
deriving from the TreeNode class and adding an instance variable that
holds a TreeNode's numeric identifier is a quick and easy way to get
this done.

ki***************@yahoo.com (Kilroy Programmer) wrote in message news:<11**************************@posting.google. com>...
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 maintained as the number of TreeNodes
increases.

Using GetHashCode() is undesirable because the resulting hash seems to
depend on the order in which the Nodes are checked.

I am hoping that after declaring a number of unique const ints in the
class constructor, I can later give each TreeNode its own unique
identifier as the TreeView is built. (Again, for easy lookup when
AfterCheck() is triggered). I need the solution to be persistent
across different instances of the program.

Does anyone have ideas on how to do this, or a different way to go
about what I'm trying to achieve? I've only been using C# for about a
week.

Nov 16 '05 #3
Sorry if I have misunderstood, but could you not store the unique Id in the
"Tag" property of the node?

"Kilroy Programmer" wrote:
I will answer my own question. In retrospect it's obvious that
deriving from the TreeNode class and adding an instance variable that
holds a TreeNode's numeric identifier is a quick and easy way to get
this done.

ki***************@yahoo.com (Kilroy Programmer) wrote in message news:<11**************************@posting.google. com>...
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 maintained as the number of TreeNodes
increases.

Using GetHashCode() is undesirable because the resulting hash seems to
depend on the order in which the Nodes are checked.

I am hoping that after declaring a number of unique const ints in the
class constructor, I can later give each TreeNode its own unique
identifier as the TreeView is built. (Again, for easy lookup when
AfterCheck() is triggered). I need the solution to be persistent
across different instances of the program.

Does anyone have ideas on how to do this, or a different way to go
about what I'm trying to achieve? I've only been using C# for about a
week.

Nov 16 '05 #4

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

Similar topics

9
by: aragon | last post by:
Hi all, is it legal to use a fully-numeric string as "name" attribute for the <select> tag in the XHTML standard? E.g.: <form action="action.php" method="get"> <select name="12345"> <option...
5
by: David Pope | last post by:
I need to create a unique number like a GUID but all numbers. Does anyone know of algorithm to do this? Thanks, David
0
by: Peter Rahm-Coffey | last post by:
I've having trouble with updating a unique index. Briefly: CREATE TABLE playlist ( playorder numeric UNIQUE NOT NULL, }; CREATE TABLE globals (
4
by: nondisclosure007 | last post by:
Hello all! I have something rather unique. I'm creating a cookie for customization for a webpage. But I want to tie the user to a machine (not friendly, I know, but for what I'm doing, it's...
4
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...
5
by: Paul | last post by:
VB.NET - VS 2005 Is it possible to create an Enum with numeric members. Example: Public Enum NumberOfDecimalPlaces Auto 1 2 3 4
16
by: Mark S. | last post by:
I'm a fan of the GUID, but the current project is looking to use a genuinely unique integer. Does the following do that? Math.Abs(System.Guid.NewGuid().GetHashCode()) TIA
4
by: Rob Stevens | last post by:
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. ...
13
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()...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.