473,387 Members | 1,603 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.

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 3340
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*********@discussions.microsoft.com> escribió en el
mensaje news:AA**********************************@microsof t.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.Equals("0"))
tnMainNode = tvTOC.Nodes.Add(descNodes[iItem].InnerText);
switch(levelNodes[iItem].InnerText)
{
case "1":
tnLevelOne = tnMainNode.Nodes.Add(descNodes[iItem].InnerText);
break;
case "2":
tnLevelTwo = tnLevelOne.Nodes.Add(descNodes[iItem].InnerText);
break;
case "3":
tnLevelThree = tnLevelTwo.Nodes.Add(descNodes[iItem].InnerText);
break;
case "4":
tbLevelFour = tnLevelThree.Nodes.Add(descNodes[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*********@discussions.microsoft.com> escribió en el
mensaje news:AA**********************************@microsof t.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 TreeNodeCollection 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.Nodes.Add(descNodes[iItem].InnerText);

use:

treeNodeEx = New TreeNodeEx(descNodes[iItem].InnerText)
treeNodeEx.MyData = blah, blah
tnMainNode.Nodes.Add(treeNodeEx)

--

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*********@discussions.microsoft.com> escribió en el
mensaje news:07**********************************@microsof t.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.Equals("0"))
tnMainNode = tvTOC.Nodes.Add(descNodes[iItem].InnerText);
switch(levelNodes[iItem].InnerText)
{
case "1":
tnLevelOne = tnMainNode.Nodes.Add(descNodes[iItem].InnerText);
break;
case "2":
tnLevelTwo = tnLevelOne.Nodes.Add(descNodes[iItem].InnerText);
break;
case "3":
tnLevelThree = tnLevelTwo.Nodes.Add(descNodes[iItem].InnerText);
break;
case "4":
tbLevelFour = tnLevelThree.Nodes.Add(descNodes[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*****@NOSPAMsogecable.com> wrote in message
news:O$**************@TK2MSFTNGP15.phx.gbl...
The TreeNodeCollection 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.Nodes.Add(descNodes[iItem].InnerText);

use:

treeNodeEx = New TreeNodeEx(descNodes[iItem].InnerText)
treeNodeEx.MyData = blah, blah
tnMainNode.Nodes.Add(treeNodeEx)

--

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*********@discussions.microsoft.com> escribió en el
mensaje news:07**********************************@microsof t.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.Equals("0"))
tnMainNode = tvTOC.Nodes.Add(descNodes[iItem].InnerText);
switch(levelNodes[iItem].InnerText)
{
case "1":
tnLevelOne = tnMainNode.Nodes.Add(descNodes[iItem].InnerText);
break;
case "2":
tnLevelTwo = tnLevelOne.Nodes.Add(descNodes[iItem].InnerText);
break;
case "3":
tnLevelThree = tnLevelTwo.Nodes.Add(descNodes[iItem].InnerText);
break;
case "4":
tbLevelFour = tnLevelThree.Nodes.Add(descNodes[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
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,...
0
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...
5
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....
0
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...
0
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...
0
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...
3
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...
3
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...
0
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...
0
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...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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: 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...
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,...

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.