I have the following code:
TreeNode parentNode1 = new TreeNode("CONNECTING RODS");
TreeViewNav.Nodes.Add(parentNode1);
string[] subNodes =
{
"STOCK", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P",
"Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
};
foreach (var node in subNodes)
{
parentNode1.ChildNodes.Add(node);
}
so im basically trying to do this but in a neater way:
TreeNode childNodeA = new TreeNode("A");
TreeNode childNodeB = new TreeNode("B");
TreeNode childNodeC = new TreeNode("C");
TreeNode childNodeD = new TreeNode("D");
TreeNode childNodeE = new TreeNode("E");
TreeNode childNodeF = new TreeNode("F");
parentNode1.ChildNodes.Add(childNodeA);
parentNode1.ChildNodes.Add(childNodeB);
parentNode1.ChildNodes.Add(childNodeC);
parentNode1.ChildNodes.Add(childNodeD);
parentNode1.ChildNodes.Add(childNodeE);
parentNode1.ChildNodes.Add(childNodeF);
Im getting the error on the parentNode1.ChildNodes.Add(node);
line.
The error is
'string' is not assignable to paramenter type 'System.Web.UI.WebControls.TreeNode'
I know its because I have made the array a string array but I dont know how else to do it any help will be really appreciated :)