473,662 Members | 2,375 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

treeview help

Hi

I'm trying to use the treeview control but having a hard time trying to
visualize how I'm going to achieve when I'm trying to do, as an example in
the end of my program I want my treeview to look something like this :-

ANIMALS
FOUR LEGS
DOGS
POODLE
GREYHOUND
BOXER
PIT BULL
CATS
TWO LEGS
HUMANS
MALE
FEMALE

VEGETABLES
GREEN
APPLIES

I'm trying to write a sub which you will pass to it for example
"ANIMALS/FOUR LEGS" or "ANIMALS/FOUR LEGS/DOGS/POODLE", and this sub will
add a note in the correct place in the node list. I have it working for one
node, but going deeper I can't think how to do it without having duplicate
code for each level (my REAL application will go down a lot of levels)

I'm not expecting anybody to write the sub (unless you want to :-) but I'm
open to some hints!

Thanks


Jul 21 '05 #1
2 1445
Hi,
I have never used treeview, but some kind of recursion should do the
trick, like (pseudo code):

void AddElement(Node currentNode, string stub)
{
int I = stub.IndexOf("/");
string newNodeName = String.Empty;

if (I < 0)
{
//this is last part, so if needed add element
//and escape
if (!ElementExists (currentNode, stub)
currentNode.Add Element(stub);
return;
}

//if we are here, there are more parts in the stub

string newNodeName = stub.SubString( I);

Node nextNode = currentNode.Fin dNodeByName(new NodeName);

if (nextNode == null)
{
//there is no subnode with that name,
//so we need to create one
nextNode = currentNode.Add NewNode(newNode Name);
}

string nextStub = stub.Substring( I, stub.Length - I);

//recurse
AddElement(next Node, nextStub);
}
Something like this :)

I Do not know if TreeNode has these methods (AddElement, FindByName,
etc.) or you have to implement them, but still this is the way.

Sunny

In article <#A************ **@TK2MSFTNGP12 .phx.gbl>, xx@nospam.com
says...
Hi

I'm trying to use the treeview control but having a hard time trying to
visualize how I'm going to achieve when I'm trying to do, as an example in
the end of my program I want my treeview to look something like this :-

ANIMALS
FOUR LEGS
DOGS
POODLE
GREYHOUND
BOXER
PIT BULL
CATS
TWO LEGS
HUMANS
MALE
FEMALE

VEGETABLES
GREEN
APPLIES

I'm trying to write a sub which you will pass to it for example
"ANIMALS/FOUR LEGS" or "ANIMALS/FOUR LEGS/DOGS/POODLE", and this sub will
add a note in the correct place in the node list. I have it working for one
node, but going deeper I can't think how to do it without having duplicate
code for each level (my REAL application will go down a lot of levels)

I'm not expecting anybody to write the sub (unless you want to :-) but I'm
open to some hints!

Thanks


Jul 21 '05 #2
Hi,
I have never used treeview, but some kind of recursion should do the
trick, like (pseudo code):

void AddElement(Node currentNode, string stub)
{
int I = stub.IndexOf("/");
string newNodeName = String.Empty;

if (I < 0)
{
//this is last part, so if needed add element
//and escape
if (!ElementExists (currentNode, stub)
currentNode.Add Element(stub);
return;
}

//if we are here, there are more parts in the stub

string newNodeName = stub.SubString( I);

Node nextNode = currentNode.Fin dNodeByName(new NodeName);

if (nextNode == null)
{
//there is no subnode with that name,
//so we need to create one
nextNode = currentNode.Add NewNode(newNode Name);
}

string nextStub = stub.Substring( I, stub.Length - I);

//recurse
AddElement(next Node, nextStub);
}
Something like this :)

I Do not know if TreeNode has these methods (AddElement, FindByName,
etc.) or you have to implement them, but still this is the way.

Sunny

In article <#A************ **@TK2MSFTNGP12 .phx.gbl>, xx@nospam.com
says...
Hi

I'm trying to use the treeview control but having a hard time trying to
visualize how I'm going to achieve when I'm trying to do, as an example in
the end of my program I want my treeview to look something like this :-

ANIMALS
FOUR LEGS
DOGS
POODLE
GREYHOUND
BOXER
PIT BULL
CATS
TWO LEGS
HUMANS
MALE
FEMALE

VEGETABLES
GREEN
APPLIES

I'm trying to write a sub which you will pass to it for example
"ANIMALS/FOUR LEGS" or "ANIMALS/FOUR LEGS/DOGS/POODLE", and this sub will
add a note in the correct place in the node list. I have it working for one
node, but going deeper I can't think how to do it without having duplicate
code for each level (my REAL application will go down a lot of levels)

I'm not expecting anybody to write the sub (unless you want to :-) but I'm
open to some hints!

Thanks


Jul 21 '05 #3

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

Similar topics

2
2421
by: Sonia Igla | last post by:
Hi. I need to perform DBLCLK on TreeView Node. I try the following: private static extern int SendMessage(IntPtr hWnd, uint msg, UInt32 wParam, UInt32 lParam); private const UInt32 WM_LBUTTONDBLCLK = 0x203; pTreeNode.TreeView.SelectedNode = pTreeNode;
4
10133
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.
2
1542
by: DJG | last post by:
I need some help with a TreeView control in VB.Net I've got a datatable with about 8000 rows. 500 are 'folders', and the other 7500 rows are 'jobs'. It's a logical representation of some data, and not a physical drive. Each row has: master_key (unique id) folder_name (name for the user to see) parent_key (the master_key of the parent folder)
3
10144
by: Jan Wrage | last post by:
Hi! I would like to implement a treeview in my existing application. It should show my entire Active-Directory structure, i.e. all Groups, Containers and OUs. Could somebody help me with that. Im trying for about 3 hours but can't get it to work. Thank you!
14
15081
by: Mr.D | last post by:
How do I save/load the contents of a Treeview to a file? I have found several good examples written i VB6, but not a single one for VB.NET. Please help. ---- Tim
3
3820
by: christof | last post by:
I've got a really easy problem, please help me: There are two pages in one I'm creating a TreeView like that: TreeView dbTree = new TreeView(); TreeNode dbTreeRoot = new TreeNode("Root"); dbTree.Nodes.Add(dbTreeRoot); .. ..
10
2349
by: p3t3r | last post by:
I have a treeview sourced from a SiteMap. I want to use 2 different CSS styles for the root level nodes. The topmost root node should not have a top border, all the other root nodes should have a top border. Is it possible to have more than 1 style at the same level (parent node) when using a SiteMap? I want it to appear something like this and I can only find a way to either have the border on all root nodes or none at all. In...
8
12752
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...
7
7836
by: Joe Cool | last post by:
Let's say I have a Treeview control on a form. Each leaf node in the Treeview has a ContextMenuStrip, each with one ToolStripMenuItem, and all ToolStripMenuItems Click event is handled by a comment event handler. How do I determine which Treeview Node signalled the menu event in the common event handler?
2
5504
by: makennedy | last post by:
Hi Experts, Please help, I am a newbie to ASP.NET 2.0 may be I am doing something wrong or there may be a bug somewhere. Basically I have a TreeView Control which I have created programmatically. And I want to bind the selection of a TreeNode (which is a record) from the database) to a DetailsView which shows the datatable record for the selected TreeView node in the Details View. I am using IDE : Visual Web Developer 2005 Express; OS=...
0
8343
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
8762
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
7365
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
6185
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
5653
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
4179
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
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
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
1992
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.