473,890 Members | 1,367 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TreeView Question

I have a treeView with nested Items, I need to set for each node in tree a
specific data like following

Root---
---Node1 (here i need to attach url for each item so when user click
it display it in DHtmlDialog)
---Node2
---Node3
so my question how to set this data for each item?
Nov 17 '05 #1
4 3406
You can create a TreeNodeEx class which inherits from TreeNode and which
contains additional properties and then you add instances of it to the
treeview. When a TreeNode is clicked, you cast back to TreeNodeEx and
retrieve the additional data.

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

"Raed Sawalha" <Ra*********@di scussions.micro soft.com> escribió en el
mensaje news:AA******** *************** ***********@mic rosoft.com...
I have a treeView with nested Items, I need to set for each node in tree a
specific data like following

Root---
---Node1 (here i need to attach url for each item so when user
click
it display it in DHtmlDialog)
---Node2
---Node3
so my question how to set this data for each item?

Nov 17 '05 #2
ok im building the tree according to a level no [0-4] extracted from XMl fiel
as following
TreeNode tnMainNode = null;
TreeNode tnLevelOne = null;
TreeNode tnLevelTwo = null;
TreeNode tnLevelThree = null;
TreeNode tbLevelFour = null;

for(int iItem = 0 ; iItem < nItems ;iItem++)
{

if(levelNodes[iItem].InnerText.Equa ls("0"))
tnMainNode = tvTOC.Nodes.Add (descNodes[iItem].InnerText);
switch(levelNod es[iItem].InnerText)
{
case "1":
tnLevelOne = tnMainNode.Node s.Add(descNodes[iItem].InnerText);
break;
case "2":
tnLevelTwo = tnLevelOne.Node s.Add(descNodes[iItem].InnerText);
break;
case "3":
tnLevelThree = tnLevelTwo.Node s.Add(descNodes[iItem].InnerText);
break;
case "4":
tbLevelFour = tnLevelThree.No des.Add(descNod es[iItem].InnerText);
break;
}
}

I created the custom node inherited from TreeNode and add my own data and
replace the TreeNode objects above with it to be

TreeNodeEx tnMainNode = null;
TreeNodeEx tnLevelOne = null;
TreeNodeEx tnLevelTwo = null;
TreeNodeEx tnLevelThree = null;
TreeNodeEx tbLevelFour = null;

but when add it return TreeNode when ..so cast it to TreeNodeEx...
exception said Specified cast is not valid...what's wrong?

"Carlos J. Quintero [VB MVP]" wrote:
You can create a TreeNodeEx class which inherits from TreeNode and which
contains additional properties and then you add instances of it to the
treeview. When a TreeNode is clicked, you cast back to TreeNodeEx and
retrieve the additional data.

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

"Raed Sawalha" <Ra*********@di scussions.micro soft.com> escribió en el
mensaje news:AA******** *************** ***********@mic rosoft.com...
I have a treeView with nested Items, I need to set for each node in tree a
specific data like following

Root---
---Node1 (here i need to attach url for each item so when user
click
it display it in DHtmlDialog)
---Node2
---Node3
so my question how to set this data for each item?


Nov 17 '05 #3
The TreeNodeCollect ion class of the Nodes property has 2 overloaded Add
methods, and you are using the one that receives the node text (which
actually adds a TreeNode object). You need to use the other one, which
receives an instance already created of a TreeNode (or a derived class). So:

Instead of:

tnLevelOne = tnMainNode.Node s.Add(descNodes[iItem].InnerText);

use:

treeNodeEx = New TreeNodeEx(desc Nodes[iItem].InnerText)
treeNodeEx.MyDa ta = blah, blah
tnMainNode.Node s.Add(treeNodeE x)

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com
"Raed Sawalha" <Ra*********@di scussions.micro soft.com> escribió en el
mensaje news:07******** *************** ***********@mic rosoft.com...
ok im building the tree according to a level no [0-4] extracted from XMl
fiel
as following
TreeNode tnMainNode = null;
TreeNode tnLevelOne = null;
TreeNode tnLevelTwo = null;
TreeNode tnLevelThree = null;
TreeNode tbLevelFour = null;

for(int iItem = 0 ; iItem < nItems ;iItem++)
{

if(levelNodes[iItem].InnerText.Equa ls("0"))
tnMainNode = tvTOC.Nodes.Add (descNodes[iItem].InnerText);
switch(levelNod es[iItem].InnerText)
{
case "1":
tnLevelOne = tnMainNode.Node s.Add(descNodes[iItem].InnerText);
break;
case "2":
tnLevelTwo = tnLevelOne.Node s.Add(descNodes[iItem].InnerText);
break;
case "3":
tnLevelThree = tnLevelTwo.Node s.Add(descNodes[iItem].InnerText);
break;
case "4":
tbLevelFour = tnLevelThree.No des.Add(descNod es[iItem].InnerText);
break;
}
}

I created the custom node inherited from TreeNode and add my own data and
replace the TreeNode objects above with it to be

TreeNodeEx tnMainNode = null;
TreeNodeEx tnLevelOne = null;
TreeNodeEx tnLevelTwo = null;
TreeNodeEx tnLevelThree = null;
TreeNodeEx tbLevelFour = null;

but when add it return TreeNode when ..so cast it to TreeNodeEx...
exception said Specified cast is not valid...what's wrong?

"Carlos J. Quintero [VB MVP]" wrote:
You can create a TreeNodeEx class which inherits from TreeNode and which
contains additional properties and then you add instances of it to the
treeview. When a TreeNode is clicked, you cast back to TreeNodeEx and
retrieve the additional data.

--


Nov 17 '05 #4
You can use the TreeNode Tag property to set it to an object.

"Carlos J. Quintero [VB MVP]" <ca*****@NOSPAM sogecable.com> wrote in message
news:O$******** ******@TK2MSFTN GP15.phx.gbl...
The TreeNodeCollect ion class of the Nodes property has 2 overloaded Add
methods, and you are using the one that receives the node text (which
actually adds a TreeNode object). You need to use the other one, which
receives an instance already created of a TreeNode (or a derived class).
So:

Instead of:

tnLevelOne = tnMainNode.Node s.Add(descNodes[iItem].InnerText);

use:

treeNodeEx = New TreeNodeEx(desc Nodes[iItem].InnerText)
treeNodeEx.MyDa ta = blah, blah
tnMainNode.Node s.Add(treeNodeE x)

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com
"Raed Sawalha" <Ra*********@di scussions.micro soft.com> escribió en el
mensaje news:07******** *************** ***********@mic rosoft.com...
ok im building the tree according to a level no [0-4] extracted from XMl
fiel
as following
TreeNode tnMainNode = null;
TreeNode tnLevelOne = null;
TreeNode tnLevelTwo = null;
TreeNode tnLevelThree = null;
TreeNode tbLevelFour = null;

for(int iItem = 0 ; iItem < nItems ;iItem++)
{

if(levelNodes[iItem].InnerText.Equa ls("0"))
tnMainNode = tvTOC.Nodes.Add (descNodes[iItem].InnerText);
switch(levelNod es[iItem].InnerText)
{
case "1":
tnLevelOne = tnMainNode.Node s.Add(descNodes[iItem].InnerText);
break;
case "2":
tnLevelTwo = tnLevelOne.Node s.Add(descNodes[iItem].InnerText);
break;
case "3":
tnLevelThree = tnLevelTwo.Node s.Add(descNodes[iItem].InnerText);
break;
case "4":
tbLevelFour = tnLevelThree.No des.Add(descNod es[iItem].InnerText);
break;
}
}

I created the custom node inherited from TreeNode and add my own data and
replace the TreeNode objects above with it to be

TreeNodeEx tnMainNode = null;
TreeNodeEx tnLevelOne = null;
TreeNodeEx tnLevelTwo = null;
TreeNodeEx tnLevelThree = null;
TreeNodeEx tbLevelFour = null;

but when add it return TreeNode when ..so cast it to TreeNodeEx...
exception said Specified cast is not valid...what's wrong?

"Carlos J. Quintero [VB MVP]" wrote:
You can create a TreeNodeEx class which inherits from TreeNode and which
contains additional properties and then you add instances of it to the
treeview. When a TreeNode is clicked, you cast back to TreeNodeEx and
retrieve the additional data.

--

Nov 17 '05 #5

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

Similar topics

3
441
by: Michael C | last post by:
Hi all, Quick question about the TreeView control. I'm using code like this to determine the currently clicked TreeNode in the TreeView. private void MyTreeView_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { currentNode = MyTreeView.GetNodeAt(e.X, e.Y); }
0
900
by: John | last post by:
Hi all, I have a puzzling question. I'm loading a treeview conrol with nodes and now need to send data with it but for it not to be shown. I need to use it later. To give an example, a datagrid could have one visible column but a couple of invisible columns with supporting data (e.g. a db key). If someone clicks on the description, one can get that key from the hidden item. Is there some way I can do this using the treeview control? I...
5
1711
by: Bart Schelkens | last post by:
Hi, i'm using the treeview from the Microsoft.Web.UI.Webcontrols.Treeview. It works fine. But my problem is that I don't get scrollbars if my treeview is too long or too wide for my frame. What can I do about this? Thx.
0
903
by: Bart Schelkens | last post by:
Hi, I'm working with the Microsoft.Web.UI.WebControls.TreeView. I've put it in a <div></div> so that it would display scrollbars whenever the text was too wide or too high. Now how can I get it to display the scrollbars when I resize my screen? I want to see those scrollbars also when I resize my screen so that I don't see the entire treeview.
0
1156
by: Patrick Olurotimi Ige | last post by:
I have a code below that i use to populate a treeview menu from the DB('m using the Treeview webcontrol). I can get the ChildRows but i want to make the "nodeProd.Text = rowProd("ProductName")" a link! I tried doing :- 'nodeProd.Text = <a href ="">" & rowProd("ProductName") &"</a> but no LUCK Any ideas?
0
955
by: Woody Splawn | last post by:
Could someone tell me what the command might be to clear *everything* out of a treeview. That is, suppose I have a treeview with numerous nodes open. I would like the user to be able to press Ctrl-C or what ever to clear out all items retrieved in the various nodes, get rid of all the pluses, and start again at the top or from scratch. How would I do this? Also, I read somewhere that using Begin Update will speed things up where...
3
1433
by: Kelvin Leung | last post by:
Hi I use Drag and Drop between 2 TreeView Control under VB.Net But I found that it cannot work when I add sub-class for each node Is it drag and drop method cannot work when the node with sub-class ? If no, any related information/reference ? Thanks a lot
3
2261
by: Shawn | last post by:
Hi. I'm working with the TreeView control in my ASP.NET 1.1 application. I have a problem I haven't been able to figure out. When I click on a node (not expand), whether it's a parent node, a child node or a leaf node then a DataGrid is populated based on the node's ID property. If I expand a node then the DataGrid is not populated. This works fine. The problem is that this doesn't work if I collapse the tree. If I collapse the tree...
0
909
by: MichaelY | last post by:
I'm using the 2.0 TreeView, and thus far have been able to get most everything out of it I need (context menus on nodes, lazy loading, etc.). However, there is a scenario in which I'm not sure what route to take. That is: 1. Refreshing the tree from the client side (without a post back - this is important) - better yet, refreshing a specific node and all of it's children. I've looked at the TreeView.js file that is pulled out of the...
0
906
by: sianan | last post by:
I am having a problem with the TreeView control. What I am trying to do, *should* be simple. When the user selects a node in my TreeView, I first check to see if the data for the object referenced by that node has changed. If it has, I want to give the user the option of either selecting the next node in the tree, or canceling, in which case the next node is not selected. The tree remains as it was, with the original node selected. (I...
0
9825
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
10828
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10467
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...
0
9638
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
8018
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
5854
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...
1
4682
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
4276
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3282
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.