I have a tree view object that I am trying to load via database calls. I'm
trying to make it generic so that I can extend and re-use it. One of the
things I want to be able to do is to load the child nodes on demand based on
the parent data (basically grouping sets of data objects by types and status
for clearer navigation).
When a user expands a node I want to call the appropriate method to get the
data. I have create a TreeViewLogic object to do all the node maintenance.
In my base class I don't know how many levels deep (it could be limitless
recursion) the tree will be so I was going to try and implement the
following approach for getting the node data.
1) base class declares a delegate called GetNodeData( node, args )
2) base class has an array of delegates GetNodeDatap[] _GetDataByLevel;
3) base class has method to point the level to a GetNodeData method
SetNodeLevelGetData(int level, GetNodeData getData)
{
_getDataMethods[level]+= new GetNodeData(getData);
}
4) the descendant class (say has three levels) can create three separate
GetNodeData methods for each level
GetNodeData1 (node, args) retrive using SP_1;
GetNodeData2 (node, args) retrive using SP_2 using parmsX, Y, Z;
GetNodeData3 (node, args) retrive using SP_3;
5) the descendant class registers its level retrieve method
SetNodeLevelGetData(1, GetNodeData1 );
SetNodeLevelGetData(2, GetNodeData2 );
SetNodeLevelGetData(3, GetNodeData3 );
6) when the node expands it calls the base class
public void GetNodeLevelData(UltraTreeNode parentNode)
{
// need logic if last level is recursive to call
_getDataMethods[UpperBound] or something.
_getDataMethods[parentNode.Level](parentNode,parentNode.GetArgs());
}
Is this methodolgy going to work? Is there a better mechanism for doing
this sort of thing?
thx
jack