I'm reading in a csv file, to create an array called 'shipsList[x]', and then I want to use this information to both create a treeview node structure, and also fill another array. The information read in to 'shipsList[x]' is:
Code:
X,parentNodeName,Y,childNodeName,Z,grandchildNodeName,val1,val2,val3,val4
Under each parent node, there are any number of child nodes, the same with the grandchild nodes under the childs. Basically, I am trying to read the 'shipsList[x]' array, and get the program to read the first value, decide if it's X, Y, or Z, and for the first two, read the next value in 'shipsList[x]', add a new node with this name, and move along. For Z, add the next item, and ignore the rest (or, add that data to another array), and move along again, until it runs out of items. However, my code below, successfully reads the parent nodes, but throws all the child nodes under the very first created parent node, as i cannot figure out how to add a child node to the most recently created parent node, and the same for the grandchild under child nodes. Heck, I haven't been able to get anywhere with the grandchildren. Got any ideas?
Code:
treeView1.BeginUpdate();
treeView1.Nodes.Clear();
int counter = 0;
for (counter = 0; counter <= 500; counter++)
{
switch (shipsList[counter])
{
case "X":
//want to create a top node and name it
treeView1.Nodes.Add(new TreeNode(shipsList[counter + 1]));
counter += 1;
break;
case "Y":
//want to create a child node under the above top node (in 'case 0:') and name it
treeView1.Nodes[0].Nodes.Add(new TreeNode(shipsList[counter + 1]));
counter += 1;
//treeView1.Nodes[nodeNumber].Nodes.Add(new TreeNode(shipsList[counter + 1]));
break;
case "Z":
//want to create a grandchild node under 'case 1:' and name it, then also
//add the attributes to shipsDataGroup
//treeView1.Nodes[2].Nodes.Add(new TreeNode(shipsList[counter + 1]));
counter += 0;
break;
}
}
treeView1.EndUpdate();
P.S. This really is not homework, this is a personal project.