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

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 1428
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.AddElement(stub);
return;
}

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

string newNodeName = stub.SubString(I);

Node nextNode = currentNode.FindNodeByName(newNodeName);

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

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

//recurse
AddElement(nextNode, 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.AddElement(stub);
return;
}

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

string newNodeName = stub.SubString(I);

Node nextNode = currentNode.FindNodeByName(newNodeName);

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

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

//recurse
AddElement(nextNode, 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
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...
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...
2
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,...
3
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...
14
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
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");...
10
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...
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...
7
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...
2
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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...

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.