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

adding nodes to treeView control dynamically at runtime

Here is the code that i have been using to add nodes dynamically, but
I cant see any child nodes being displayed on the treeView... all i
can see the root node "Network". I have been trying to develop a
modelling soft. as an educational project.

// event fires when shape is added to visio control

if (vsoMaster.Name == "Ellipse")
{

addedShape.Name=(string)"Node" +
NodeCount.ToString(); // Ellipse01
addedShape.Text = (string)"Node" +
NodeCount.ToString();
MessageBox.Show(addedShape.Name.ToString()); //
does how here
nodeArray = new Node[NodeCount];
nodeArray[NodeCount].Name="Node" +
NodeCount.ToString() ;
nodeArray[NodeCount].Id = NodeCount.ToString();
treeViewForm.NodeAdd(nodeArray[NodeCount].Name.ToString()); // add
node to trieview
MessageBox.Show(nodeArray[NodeCount].Name.ToString()); // does not
show a messagebox here why????
NodeCount++;
}

here is the treeView form :
public partial class TreeViewForm : Form
{
TreeNode ParentNode;

public TreeViewForm()
{
InitializeComponent();
}

private void TreeViewForm_Load(object sender, EventArgs e)
{

ParentNode = treeView1.Nodes.Add("Network");
ParentNode.Expand();
}

public void NodeAdd( string nodeName)
{
ParentNode.Nodes.Add(nodeName);
ParentNode.Expand();
}

private void treeView1_NodeMouseDoubleClick(object sender,
TreeNodeMouseClickEventArgs e)
{
string NodeId=treeView1.SelectedNode.Text;

}
}

Need help
Regards
Nov 16 '07 #1
1 15032
Well these lines won't achieve much:

nodeArray = new Node[NodeCount];

just creates a new array with NodeCount elements - the previous array has
gone.

nodeArray[NodeCount].Name="Node" + NodeCount.ToString() ;

I'm surprised you dont get an error here. Array are indexed from 0 so
nodeArray[NodeCount] won't exist.

If this data is dynamic the you're better off using a list.
List<NodenodeList = new List<Node>();
....
nodeList.Add(="Node" +
NodeCount.ToString() ;
);

but to be honest I cannot see want you want the array for.
"weird0" wrote:
Here is the code that i have been using to add nodes dynamically, but
I cant see any child nodes being displayed on the treeView... all i
can see the root node "Network". I have been trying to develop a
modelling soft. as an educational project.

// event fires when shape is added to visio control

if (vsoMaster.Name == "Ellipse")
{

addedShape.Name=(string)"Node" +
NodeCount.ToString(); // Ellipse01
addedShape.Text = (string)"Node" +
NodeCount.ToString();
MessageBox.Show(addedShape.Name.ToString()); //
does how here
nodeArray = new Node[NodeCount];
nodeArray[NodeCount].Name="Node" +
NodeCount.ToString() ;
nodeArray[NodeCount].Id = NodeCount.ToString();
treeViewForm.NodeAdd(nodeArray[NodeCount].Name.ToString()); // add
node to trieview
MessageBox.Show(nodeArray[NodeCount].Name.ToString()); // does not
show a messagebox here why????
NodeCount++;
}

here is the treeView form :
public partial class TreeViewForm : Form
{
TreeNode ParentNode;

public TreeViewForm()
{
InitializeComponent();
}

private void TreeViewForm_Load(object sender, EventArgs e)
{

ParentNode = treeView1.Nodes.Add("Network");
ParentNode.Expand();
}

public void NodeAdd( string nodeName)
{
ParentNode.Nodes.Add(nodeName);
ParentNode.Expand();
}

private void treeView1_NodeMouseDoubleClick(object sender,
TreeNodeMouseClickEventArgs e)
{
string NodeId=treeView1.SelectedNode.Text;

}
}

Need help
Regards
Nov 20 '07 #2

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

Similar topics

4
by: ghanley | last post by:
Hi Guys, I need some help with a problem related to the looping through a recordset to display on a tree view control. My table has no Primary key - because duplicates are allowed. ID ...
10
by: Dan Nash | last post by:
Hi peeps.. Im using the TreeView control from IE COntrols to create a directory structure, and trying to do it recursively. The code works, but my question is simply how can I make the subdirs...
4
by: pmcguire | last post by:
I have a treeview with a lot of nodes. I want to load only the nodes that are initially visible when the form loads, and then continue to populate it in background and/or when the nodes are required...
1
by: garyusenet | last post by:
Hi All, I'm eagerly anticipating what you have to say on something that's stumped me over the weekend. I'm writing a small application which utilises a treeview control. I've figured out how to...
0
by: drop | last post by:
Hi, I'm currently working with the Treeview control in ASP .Net 2.0. The tree is filled dynamically based on data contained in a MySQL Database. Here is the exact behavior I want : 1 - User...
0
by: Kulbir | last post by:
I am a beginner in C#.net Windows programming. I have two forms - Form1 and Form2. On Form1, I have a splitter. In one of the panel of splitter, I have put a Panel Control(Panel2). I have...
0
debasisdas
by: debasisdas | last post by:
Select Microsoft windows common controls 6.0 (SP6) from components Add a TreeView control to the form. Add a ImageList control to the form. Add some bitmaps to the imagelist. Set the name of...
0
debasisdas
by: debasisdas | last post by:
This sample code displays employee name in the treeview control from the emp table of Scott schema in oracle database. To start with Select Microsoft windows common controls 6.0 (SP6) from...
1
by: Bart Steur | last post by:
Hi As a VB6 user I'm unfamiliar with the Treeview control of VB2005. I read it was changed but I have a hard time finding the right help/samples for my problem. In VB6 you had 1 collection,...
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: 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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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.