473,387 Members | 1,485 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,387 software developers and data experts.

Inheriting the TreeView problem...

In my treeview, I need each node to hold a "value", not just
text/label. Kind of like how a ListBox item has text, and a value
associated with it. I need this because when a node is clicked, i need
to get the "value" behind the node and then use it do do something.

Anyway, I made a custom treenode class that inherits from Treenode, and
added a property called "value".

I was able to successfully create the Treeview programmatically from a
database, which includes the "value" property that i made.

Here's my problem: The routine I have to run when a user clicks a node
is this:

Private Sub treeview_AfterSelect(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles
treeview.AfterSelect
'do something with e.Node.value
End Sub

Because my "value" property was added in my custom class, it is not
available to use in TreeViewEventArgs. So e.Node.Value will not work.
How can I do this?...i'm stumped!

Thanks for your help!
John

Nov 21 '05 #1
3 2348

You can cast it.

DirectCast(e.Node, MyCustomTreeNode).Value

btw, perhaps you use the Tag property instead of a custom class?

HTH,

Sam
On 26 Jan 2005 07:38:21 -0800, "johnb41" <or****@informatik.com>
wrote:
In my treeview, I need each node to hold a "value", not just
text/label. Kind of like how a ListBox item has text, and a value
associated with it. I need this because when a node is clicked, i need
to get the "value" behind the node and then use it do do something.

Anyway, I made a custom treenode class that inherits from Treenode, and
added a property called "value".

I was able to successfully create the Treeview programmatically from a
database, which includes the "value" property that i made.

Here's my problem: The routine I have to run when a user clicks a node
is this:

Private Sub treeview_AfterSelect(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles
treeview.AfterSelect
'do something with e.Node.value
End Sub

Because my "value" property was added in my custom class, it is not
available to use in TreeViewEventArgs. So e.Node.Value will not work.
How can I do this?...i'm stumped!

Thanks for your help!
John


Nov 21 '05 #2
Quick and dirty, the important thing is the directcast in the afterselect
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
_ Handles MyBase.Load
TreeView1.Nodes.Add(New MyTreeNode("Belgium", "BE"))
TreeView1.Nodes.Add(New MyTreeNode("Netherlands", "NL"))
TreeView1.Nodes.Add(New MyTreeNode("France", "FR"))
TreeView1.Nodes.Add(New MyTreeNode("Germany", "GER"))
End Sub

Private Sub TreeView1_AfterSelect(ByVal sender As Object, ByVal e As _
System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
MsgBox(DirectCast(TreeView1.SelectedNode, MyTreeNode).value)
End Sub

Public Class MyTreeNode
Inherits TreeNode
Private myvalue As String
Public Property value() As String
Get
Return myvalue
End Get
Set(ByVal Value As String)
myvalue = Value
End Set
End Property
Sub New(ByVal text As String, ByVal value As String)
MyBase.New()
Me.Text = text
Me.value = value
End Sub

End Class

hth Greetz Peter
"Samuel R. Neff" <bl****@newsgroup.nospam> wrote in message
news:ch********************************@4ax.com...

You can cast it.

DirectCast(e.Node, MyCustomTreeNode).Value

btw, perhaps you use the Tag property instead of a custom class?

HTH,

Sam
On 26 Jan 2005 07:38:21 -0800, "johnb41" <or****@informatik.com>
wrote:
In my treeview, I need each node to hold a "value", not just
text/label. Kind of like how a ListBox item has text, and a value
associated with it. I need this because when a node is clicked, i need
to get the "value" behind the node and then use it do do something.

Anyway, I made a custom treenode class that inherits from Treenode, and
added a property called "value".

I was able to successfully create the Treeview programmatically from a
database, which includes the "value" property that i made.

Here's my problem: The routine I have to run when a user clicks a node
is this:

Private Sub treeview_AfterSelect(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles
treeview.AfterSelect
'do something with e.Node.value
End Sub

Because my "value" property was added in my custom class, it is not
available to use in TreeViewEventArgs. So e.Node.Value will not work.
How can I do this?...i'm stumped!

Thanks for your help!
John

Nov 21 '05 #3
Thanks Samuel and Peter!

The DirectCast thing did the trick. Amazing. I thought the fix would
need a large amount of code.

Thanks again!
John

Nov 21 '05 #4

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

Similar topics

1
by: meh | last post by:
If I create a treeView sould I get the same member variables as a treeView. I dont see MyTree.Text or MyTree.Tag. Do I have to define them or have I left something out. Any help, docs or examples...
4
by: Karim El Jed | last post by:
Hi, I'm trying to expand a special Node of my TreeView from Codebehind. I have a TreeView on a page for navigating to another site. On the other tsite here is the same TreeView more precisely a...
14
by: Evan Kontos | last post by:
I am trying to implement a Treeview w/an XML file and I even copied and pasted examples from MSDN but can't get them to work. Any suggestions welcome. XML File <TREENODES> <TREENODE...
2
by: Charles Law | last post by:
I want a set of controls that all have a border, like a group box. I thought I would create a base control containing just a group box from which my set of controls could inherit. Assuming that...
4
by: Jeff Beem | last post by:
I have a class that inherits from TreeView. The treeview has tooltips for the nodes but they're showing up behind the form. Has anyone seen this? Are there any known fixes? Thanks in advance,...
4
by: christof | last post by:
It'll be really easy...Sorry for that question: I've got a MasterPage <%@ Master Language="C#" ClassName="MasterP" %> and some slave.aspx.<%@ Page Language="C#" MasterPageFile="~/Master1.master"...
3
by: William Sullivan | last post by:
I desperately want to replace my hand-made ajax treeview with the 2.0 TreeView. The webpage I'm designing uses the postbacks to dynamically fill the treeview. The reason why I'm doing this is...
8
by: Matt MacDonald | last post by:
Hi All, I have a form that displays hierarchical categories in a treeview. Ok so far so good. What I was to do is have users be able to select a node in the treeview as part of filling out the...
1
by: Nikron | last post by:
Hi, I'm having an issue with the ASP.NET 2.0 Treeview control and persisting its' state accross requests. My Control is embedded within a master page and is used for site navigation. My problem...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.