I have a bunch of NodeTypes that I want to use throughout my project, in several different FTVs, without having to redefine them everytime.
I'm trying to do this by defining a class, which contains a static NodeTypeCollection, initialized by a static constructor:
public class TreeView {
static public readonly Ftv.TreeNodeTypeCollection NodeTypes;
static TreeView() {
//Create node types
NodeTypes = new Ftv.TreeNodeTypeCollection();
Ftv.TreeNodeType nt1 = new Ftv.TreeNodeType();
nt1.Name = "nt1";
NodeTypes.Add(nt1);
Ftv.TreeNodeType nt2= new Ftv.TreeNodeType();
nt2.Name = "nt2";
NodeTypes.Add(nt2);
}
}
}
In an ASPX page, I then add a FlyTreeView, and try and populate its NodeTypes TreeNodeTypeCollection from the static one defined above:
FlyTreeView ft;
// ... some stuff here
// In the Page_Load event handler:
foreach(TreeNodeType nt in TreeView.NodeTypes) ft.NodeTypes.Add(nt);
The Add method on the last line throws an exception: "This object is already in collection", when ft.NodeTypes is indeed empty before the call.
This does not happen if nt is a locally defined NodeType (in the Page_Load handler).
Any idea what can cause this ?
Any smarter way of achieving the same result (defining [once] a bunch of TreeNodeTypes that can be re-used in several pages) ?
Thanks,
Pyt.