ok im building the tree according to a level no [0-4] extracted from XMl
fiel
as following
TreeNode tnMainNode = null;
TreeNode tnLevelOne = null;
TreeNode tnLevelTwo = null;
TreeNode tnLevelThree = null;
TreeNode tbLevelFour = null;
for(int iItem = 0 ; iItem < nItems ;iItem++)
{
if(levelNodes[iItem].InnerText.Equals("0"))
tnMainNode = tvTOC.Nodes.Add(descNodes[iItem].InnerText);
switch(levelNodes[iItem].InnerText)
{
case "1":
tnLevelOne = tnMainNode.Nodes.Add(descNodes[iItem].InnerText);
break;
case "2":
tnLevelTwo = tnLevelOne.Nodes.Add(descNodes[iItem].InnerText);
break;
case "3":
tnLevelThree = tnLevelTwo.Nodes.Add(descNodes[iItem].InnerText);
break;
case "4":
tbLevelFour = tnLevelThree.Nodes.Add(descNodes[iItem].InnerText);
break;
}
}
I created the custom node inherited from TreeNode and add my own data and
replace the TreeNode objects above with it to be
TreeNodeEx tnMainNode = null;
TreeNodeEx tnLevelOne = null;
TreeNodeEx tnLevelTwo = null;
TreeNodeEx tnLevelThree = null;
TreeNodeEx tbLevelFour = null;
but when add it return TreeNode when ..so cast it to TreeNodeEx...
exception said Specified cast is not valid...what's wrong?
Carlos J. Quintero said:
You can create a TreeNodeEx class which inherits from TreeNode and which
contains additional properties and then you add instances of it to the
treeview. When a TreeNode is clicked, you cast back to TreeNodeEx and
retrieve the additional data.