PC Review


Reply
Thread Tools Rate Thread

adding nodes to treeView control dynamically at runtime

 
 
weird0
Guest
Posts: n/a
 
      16th Nov 2007
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
 
Reply With Quote
 
 
 
 
=?Utf-8?B?U2ltb24gSGVmZmVy?=
Guest
Posts: n/a
 
      20th Nov 2007
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<Node> nodeList = 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
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting TreeView nodes at runtime. Mr. X. Microsoft C# .NET 0 7th May 2011 12:43 PM
Specifying the parent when adding treeview nodes? SQACSharp Microsoft C# .NET 7 28th Nov 2007 08:00 AM
Changing TreeView nodes font dynamically =?Utf-8?B?VGVkLUJH?= Microsoft Dot NET Framework Forms 2 7th Jan 2005 06:57 PM
Adding nodes to treeview =?Utf-8?B?Sm9obg==?= Microsoft Excel Programming 3 1st Dec 2004 09:07 PM
Adding Nodes to a TreeView sho_nuff Microsoft C# .NET 3 17th Jan 2004 11:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:07 AM.