adding nodes to treeView control dynamically at runtime

W

weird0

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
 
G

Guest

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 said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top