By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,934 Members | 1,318 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,934 IT Pros & Developers. It's quick & easy.

adding nodes to treeView control dynamically at runtime

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.