473,804 Members | 2,143 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get treenode value from vb.net 2005 winforms treeview

Hi all...

Perhaps I'm not going about this the right way, but I wondered if
anyone can help?

I have a treeview which populates from a datatable using a parent/
child relationship. It stores a company/branch hierarchical structure
and show areas/regions/branches etc by name in it's nodes.

What I need to be able to do is select a node (by clicking on the
branch name etc) and return an integer value for the given hierarchy
point so that I can save data based on this integer value. The reason
I need this integer is because branches etc within the company
hierarchy may be the same, but reside in different trees of the
treeview.

I've noticed there's no Node.Value or anything and wondered if anyone
had had the same problem or if anyone could think of a way around this
problem?

Thanks

Mar 6 '07 #1
4 8108
I'd also like to know how to dynamically set a SelectedNode and keep
it highlighted after the control has lost focus...

On 6 Mar, 12:34, "Karl Rhodes" <googlegro...@t lbsolutions.com wrote:
Hi all...

Perhaps I'm not going about this the right way, but I wondered if
anyone can help?

I have a treeview which populates from a datatable using a parent/
child relationship. It stores a company/branch hierarchical structure
and show areas/regions/branches etc by name in it's nodes.

What I need to be able to do is select a node (by clicking on the
branch name etc) and return an integer value for the given hierarchy
point so that I can save data based on this integer value. The reason
I need this integer is because branches etc within the company
hierarchy may be the same, but reside in different trees of the
treeview.

I've noticed there's no Node.Value or anything and wondered if anyone
had had the same problem or if anyone could think of a way around this
problem?

Thanks

Mar 6 '07 #2

There's nothing to stop you creating your own TreeNode [class] and
adding whatever data fields you want to it, as in

Class CustomNode
Inherits TreeNode

Public Sub New()
MyBase.New()
End Sub

Public Sub New( value as ... )
Me.Value = value
End Sub

Public Property Value() As ...
. . .
End Property

End Class

.... then ...

Dim oTreeNode as New CustomNode( SomeValue )
tree1.Nodes.add (oTreeNode)

Then, when you click on any TreeNode, test its type and, if it's one of
yours, cast it and work with it:

Sub Tree1_AfterSele ct( ... ) Handles tree1.AfterSele ct

If TypeOf e.Node Is CustomNode Then
With DirectCast( e.Node, CustomNode )
DoSomethingWith ( .Value )
End With
Else
End If

End Sub

Setting the SelectedNode is as easy as .. er .. setting the
SelectedNode, as in

tree1.SelectedN ode = oTreeNode

oTreeNode.Ensur eVisible ' make sure we can see the new selection
tree1.HideSelec tion = False ' make sure it /stays/ highlighted

HTH,
Phill W.

Karl Rhodes wrote:
I'd also like to know how to dynamically set a SelectedNode and keep
it highlighted after the control has lost focus...
On 6 Mar, 12:34, "Karl Rhodes" <googlegro...@t lbsolutions.com wrote:
>I have a treeview which populates from a datatable using a parent/
child relationship. It stores a company/branch hierarchical structure
and show areas/regions/branches etc by name in it's nodes.
.. . .
>I've noticed there's no Node.Value or anything and wondered if anyone
had had the same problem or if anyone could think of a way around this
problem?
Mar 6 '07 #3
On 6 Mar, 15:18, "Phill W." <p-.-a-.-w-a-r...@-o-p-e-n-.-a-c-.-u-k>
wrote:
There's nothing to stop you creating your own TreeNode [class] and
adding whatever data fields you want to it, as in

Class CustomNode
Inherits TreeNode

Public Sub New()
MyBase.New()
End Sub

Public Sub New( value as ... )
Me.Value = value
End Sub

Public Property Value() As ...
. . .
End Property

End Class

... then ...

Dim oTreeNode as New CustomNode( SomeValue )
tree1.Nodes.add (oTreeNode)

Then, when you click on any TreeNode, test its type and, if it's one of
yours, cast it and work with it:

Sub Tree1_AfterSele ct( ... ) Handles tree1.AfterSele ct

If TypeOf e.Node Is CustomNode Then
With DirectCast( e.Node, CustomNode )
DoSomethingWith ( .Value )
End With
Else
End If

End Sub
Thanks. I'll have a go at that!
>
Setting the SelectedNode is as easy as .. er .. setting the
SelectedNode, as in

tree1.SelectedN ode = oTreeNode
Oh yeah, silly me! :)

>
oTreeNode.Ensur eVisible ' make sure we can see the new selection
tree1.HideSelec tion = False ' make sure it /stays/ highlighted

HTH,
Phill W.


Mar 6 '07 #4
On Mar 6, 10:54 am, "Karl Rhodes" <googlegro...@t lbsolutions.com >
wrote:
On 6 Mar, 15:18, "Phill W." <p-.-a-.-w-a-r...@-o-p-e-n-.-a-c-.-u-k>
wrote:
There's nothing to stop you creating your own TreeNode [class] and
adding whatever data fields you want to it, as in
Class CustomNode
Inherits TreeNode
Public Sub New()
MyBase.New()
End Sub
Public Sub New( value as ... )
Me.Value = value
End Sub
Public Property Value() As ...
. . .
End Property
End Class
... then ...
Dim oTreeNode as New CustomNode( SomeValue )
tree1.Nodes.add (oTreeNode)
Then, when you click on any TreeNode, test its type and, if it's one of
yours, cast it and work with it:
Sub Tree1_AfterSele ct( ... ) Handles tree1.AfterSele ct
If TypeOf e.Node Is CustomNode Then
With DirectCast( e.Node, CustomNode )
DoSomethingWith ( .Value )
End With
Else
End If
End Sub

Thanks. I'll have a go at that!
Setting the SelectedNode is as easy as .. er .. setting the
SelectedNode, as in
tree1.SelectedN ode = oTreeNode

Oh yeah, silly me! :)
oTreeNode.Ensur eVisible ' make sure we can see the new selection
tree1.HideSelec tion = False ' make sure it /stays/ highlighted
HTH,
Phill W.

You can use the .Tag property of the Treenode Object to store the data
that you want to associate with the node. It accepts any object.

See the msdn documentation linked below for more information
http://msdn2.microsoft.com/en-us/lib...enode.tag.aspx

Mar 6 '07 #5

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

Similar topics

6
5735
by: Dean L. Howen | last post by:
Hi, I want to add some attributes to TreeNode, so I create a new class MyNode that inheritance from System.Windows.Forms.TreeNode, I want to TreeView use MyNode instead of TreeNode, so I can manipulate with new attributes How can? Please give me some ideas, Thanks. Because the TreeNode doesn't have Value Property which contents value behind
5
10239
by: nevin | last post by:
Hi, If I have a TreeView with loads of Nodes and they all have children etc, how do I find the index of a given node when I only know the Text value? If I use TreeView.Nodes.IndexOf(new TreeNode(textvalueofname)) it always returns -1 and a TreeView.Nodes.Contains(etc.. always is false. I expect that it is only looking in the local Nodes collection rather than every single node in the TreeView. So how do I easily find any given node in...
9
12727
by: Mark Allison | last post by:
Hi there, I'm still very much a newbie to C#, and would like to derive from TreeNode to extend the TreeNode class. Here's test program: http://www.vkarlsen.no/pastebin/default.asp?id=4090 I get an error on line 0077 saying: "An unhandled exception of type 'System.InvalidCastException' occurred
6
3733
by: Craig Lister | last post by:
I have a treeview with a Root, a Contact Type, and a Contact. Like MSN Messenger. Is there a way that I can say something like if treenode.tag is classContact then string Surname = treenode.tag.surname And somehow, each time, I create the node, I can assign the object of that classContact to that node ?
3
1843
by: markaelkins | last post by:
Hi. I am trying to enter a variable in the treenodesrc of a treenode. I am basically trying to send an ID variable into sql to return different records. I've searched everywhere and cannot find the answer. I'd appreciate and help. Thanks. What I'm doing is creating a treeview with the structure as follows (this is the expanded view): - Item Status - Item Status Details
0
1343
by: Corky Whiteboard | last post by:
I have a Winforms treeview with subclassed treenodes. The treeview has "ShowNodeToolTips" set to true. The text is showing for each node, but it is not formatted 'pretty' - it comes out in one long line. Is there some way to get the formatting similar to what's available with the standard "ToolTip" windows control? This control seems only to work with other winforms controls, which a treenode is not. Thanx. Corky Whiteboard
3
4045
by: tanya foster | last post by:
Hello, I am re-writing a visual basic .net application(visual studio 2003) in an asp.net application(visual studio 2005). The vb.net application relied on a treeview and hence, treenodes. The treeview and treenode class in asp.net is limited compared to vb.net's. In vb.net, the treenode had a nextnode property which was equivalent to finding the next sibling of the treenode. asp.net's treenode has a child property and a parent property....
3
13816
by: Jeff | last post by:
Hey ..NET 2.0 I'm trying to search a TreeView control for a specific TreeNode The code below doesn't work because it only searches the the top level of the nodes. I would like to program it so that it can find a TreeNode anywhere in the TreeView... any suggestions on how to implement it ??
0
940
by: vincent90152900 | last post by:
How to pop up different text base on the selected TreeNode? I want to pop up different Text base on the selected TreeNode of the TreeView component. So, I create a TreeView and a ModalPopupExtender. Following is my codes. Default.aspx <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:TreeView ID="TreeView1" runat="server" OnSelectedNodeChanged="TreeView1_SelectedNodeChanged"> ...
0
9715
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
9595
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,...
0
9176
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...
1
7643
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6869
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
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4314
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
3836
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3003
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.