473,405 Members | 2,272 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,405 software developers and data experts.

Targetting treeview node by name

116 64KB
Hi

I am creating treeview nodes at runtime via the following method.

Expand|Select|Wrap|Line Numbers
  1. Dim Node As New TreeNode
  2. Node.Text = "John"
  3. Node.Name = "UK1243_T"
  4. Nodes.Add(Node)
  5.  
I then need to alter the node Text based on the node Name. So I try to code something that looks for node name "UK1243_T" and then dynamically alter the text - but nothing I'm trying is working as it seems I need a key for the node. The Find method also seems to fail.

Anyone any ideas?
Aug 13 '13 #1
4 2933
robertybob
116 64KB
Don't worry about it.... I can target a node using Treeview.Nodes.Item("UK1243_T").Tag method so I've no idea why Treeview.Nodes.Item("UK1243_T").Text = "Johnny" fails every time.

But must be a problem at my end...
Aug 13 '13 #2
robertybob
116 64KB
Ok - the problem is this..... never come across this before.

Expand|Select|Wrap|Line Numbers
  1. Dim thisnode As String = "UK" & id.ToString
  2.  & "_T"
  3. Treeview.Nodes.Item(thisnode).Text = "Johnny"
  4.  
It fails because it is actually looking for a node with the name 'thisnode' instead of reading the value of thisnode into the code. So it says Treeview.Nodes.Item(thisnode) doesn't exist - which is true - but it should be looking for Treeview.Nodes.Item("UK1243_T").

Any suggestions?
Aug 13 '13 #3
Killer42
8,435 Expert 8TB
@robertybob
Sorry to see you're not getting any responses here. (And that my above quote of part of your message apparently didn't work, but that's another story.)

I don't have a lot of experience with tree nodes, but it seems questionable that VB would suddenly use the name rather than the value of a variable, in evaluating such an expression. I'd suggest a more likely explanation is something like trying to use a variable out of scope.

For example, in your post you showed the definition of thisnode immediately before where it was used. I realise this is for illustration purposes, and is probably not where things are actually located in the code. In the real world, could you have defined thisnode in a different Sub or something, so the variable actually doesn't exist at the point where you used it? If that's the case, then VB would create a new variable called thisnode, of the default type (variant I think). Since the new variable has no value, I belive that would result in you trying to reference Treeview.Nodes.Item(0).Text.

(I'm assuming you're working with VB6. If you're using VB.Net it probably works differently, and you probably should ignore the following advice.)

To eliminate this as a possible source of your error, insert the code Option Explicit at the top of each module (including forms). "explicit" means that you cannot use a variable without first creating it. Instead of just going ahead and creating a new variable for you, the compiler will report an error. You'd be amazed at how many bugs are prevented this way; a mis-typed variable name can be a tough thing to track down.

To prevent such problems in future (regardless of whether it was the cause of this particular issue) you should go to your options and turn on "Require variable declaration". That causes VB to insert Option Explicit in every new module from now on.
Aug 23 '13 #4
robertybob
116 64KB
Thanks Killer.

I actually recoded this to deal with name changes whilst building the tree which seems fine. I haven't looked further into why the original treenode name was failing but will try to check the options explicit etc.

All the best.
Aug 27 '13 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Saradhi | last post by:
Hi All, Here I am facing a performance problem with the TreeView Node renaming. I am displaying a hierarchy Data in a treeview in my Windows C# Application. My tree view represents an...
1
by: JustinG | last post by:
I am relativley new to C#, and I am trying to write code using the compact framework, that will allow a handheld user to hit enter while a treeview node is selected, which will then do something...
0
by: Devhead | last post by:
I changed the treeview node text to bold and changed color "successfully". However, the node text was truncated and when i did a tree refresh the node formatting was gone. What do i need to do to...
6
by: Tim | last post by:
Hi I have a form with a treeview on it. When I select a particular node it adds/shows a tab on the form. The treeview node remains selected as it should. The user can close the tab or remove the...
2
by: ONIL | last post by:
I have a treeview in my ASP.NET vb.net application.when someone selects a node on the treeview How do I set the node name myNodeName = TreeView1.Nodes(TreeView1.SelectedNodeIndex).Text The...
4
by: Yavuz Bogazci | last post by:
Hi, i have created a treeview and this works nice. I have now a problem: I want to store 2 more Information to each Treeview Node like UserID and CompanyID. How can i do that? Thanks Yavuz...
8
by: Don Wash | last post by:
Hi There! I'm using VB.NET to create a TreeView application and unfortunately I could not find "Key" property in Node items of the TreeView. We used to have "Key" property in TreeView node...
2
by: Christian Rühl | last post by:
heyho, guys! here's another question for you now: i built an iterator to get all the nodes with a certain attribute in an xml dom. it all looks like this (i'm using .NET framework 1.1) ...
3
by: Michael_Burgess | last post by:
Hi there, I've looked around the different groups and still can't figure this out without resorting to scrappy code............ I want to programtically select and highlight a TreeView node,...
1
by: R.A.F. | last post by:
Hi, I would like simulate a mouse click on on of my treeview nodes when my form opens. for that i was thinking to use the same simple way as under C++ : SendMessage(TreeView.Nodes.Handle,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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,...
0
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...
0
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,...
0
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...

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.