473,761 Members | 2,384 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 programmaticall y 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_AfterS elect(ByVal sender As System.Object,
ByVal e As System.Windows. Forms.TreeViewE ventArgs) Handles
treeview.AfterS elect
'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 TreeViewEventAr gs. 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 2369

You can cast it.

DirectCast(e.No de, MyCustomTreeNod e).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****@informa tik.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 programmaticall y 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_AfterS elect(ByVal sender As System.Object,
ByVal e As System.Windows. Forms.TreeViewE ventArgs) Handles
treeview.After Select
'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 TreeViewEventAr gs. 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(ByVa l sender As Object, ByVal e As System.EventArg s)
_ Handles MyBase.Load
TreeView1.Nodes .Add(New MyTreeNode("Bel gium", "BE"))
TreeView1.Nodes .Add(New MyTreeNode("Net herlands", "NL"))
TreeView1.Nodes .Add(New MyTreeNode("Fra nce", "FR"))
TreeView1.Nodes .Add(New MyTreeNode("Ger many", "GER"))
End Sub

Private Sub TreeView1_After Select(ByVal sender As Object, ByVal e As _
System.Windows. Forms.TreeViewE ventArgs) Handles TreeView1.After Select
MsgBox(DirectCa st(TreeView1.Se lectedNode, MyTreeNode).val ue)
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****@newsgro up.nospam> wrote in message
news:ch******** *************** *********@4ax.c om...

You can cast it.

DirectCast(e.No de, MyCustomTreeNod e).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****@informa tik.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 programmaticall y 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_AfterS elect(ByVal sender As System.Object,
ByVal e As System.Windows. Forms.TreeViewE ventArgs) Handles
treeview.After Select
'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 TreeViewEventAr gs. 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
1078
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 would be greatly appreciated tia meh public class MyTree : TreeView {
4
10139
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 new TreeView with the same nodes ;) So I would like to keep the expanding state of the first Tree for the second one on the next page. At least the last selected node (path will be saved in query string) should be expanded.
14
6834
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 TEXT="Document-1"> <TREENODE TEXT="Folder-1" EXPANDED="true"> <TREENODE TEXT="Document-2" />
2
1813
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 this is the right approach (please tell me if it is not), how then do I make it so that the group box cannot be moved around on my set of controls, but is also able to act as container for other controls? If I leave the modifier of the group box...
4
2862
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, Jeff Beem
4
1389
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" AutoEventWireup="true" CodeFile="ShowDatabases.aspx.cs" Inherits="ShowDatabases" Title="Untitled Page" %><%@ MasterType VirtualPath="Master1.master" %> In the slave page I'm creting and populating a TreeView which I would like to pass to my...
3
1638
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 because my tree is ENORMOUS. It can possibly hold millions of nodes. The problem is keeping this treeview constrained as a user clicks through the nodes. I've tried putting it in a DIV with a set width and height, but the problem is that when you...
8
12775
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 form. I only want to allow single selection, so using checkboxes is out of the question. It works as is, but it makes the form very cumbersome if every time that a user selects a node, the whole page has to reload. Is there a way to have a node...
1
3602
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 is that the user wants to know which page they are currently on and therefore I need to highlight the selected node. The problem is I lose state whenever the user selects a node and is redirected to another page. Thanks in advance
0
9336
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,...
1
9902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9765
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...
1
7327
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
6603
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
5215
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
5364
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3866
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
3
3446
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.