Loading a Treeview from database, infinite sub nodes

  • Thread starter Thread starter Ben
  • Start date Start date
B

Ben

Hi

We have the below details:

Order_Base
CustomerNo, OrderNo, OrderItemNo.....

Order_Detail
OrderItemNo, ParentItemNo, Desc......

Order_Detail.ParentItemNo is a FK for Order_Base.OrderItemNo

There is also the ability for Order_Detail.ParentItemNo to relate to another
higher level record of Order_Detail.ParentItemNo

(dont blame me for the database design)

We want to display these details in a Tree View:

1Order_Base
2 Order_Detail which relates to Order_Base (Order_Detail.ParentItemNo =
Order_Base.OrderItemNo)
3 Order_Detail which relates to parent record Order_Detail
(Order_Detail.ParentItemNo = Order_Detail.OrderItemNo)
4 Order_Detail which relates to parent record Order_Detail
(Order_Detail.ParentItemNo = Order_Detail.OrderItemNo)
5 Order_Detail which relates to parent record Order_Detail
(Order_Detail.ParentItemNo = Order_Detail.OrderItemNo)
6 Order_Detail which relates to parent record Order_Detail
(Order_Detail.ParentItemNo = Order_Detail.OrderItemNo)

The problem I have is that the quantity of sub items could go on forever,
the sql select statement for level 3 and beyond should be identical with
only the parent variable changed.

I am having problems creating re-usable code so that I can loop though them
past stage 2, my code currenlty has selected all items at level 1 and two
and they are all there fine. but how do I continue from here?

Any help would be very much appreicated

Thanks
B
 
Ben said:
The problem I have is that the quantity of sub items could go on forever,
the sql select statement for level 3 and beyond should be identical with
only the parent variable changed.

I am having problems creating re-usable code so that I can loop though them
past stage 2, my code currenlty has selected all items at level 1 and two
and they are all there fine. but how do I continue from here?

Let your User do the looping ....

If you start unravelling things to this sort of depth all in one go, the
vast majority of users are going to die of boredom.

If they want to drill down that far, by all means let them, and just
expand each level of the tree as they go.

HTH,
Phill W.
 
Thanks Phill

I sorted out of couple of levels of nodes and, as you say, started to die of
boredom!

How can I add the expansion pluses to each item to indicate to the user that
there maybe something below (before I have loaded them).

Thanks
B
 
Actually Scap that, I will load the window with 2 levels and then load a
subsequent one level on each expansion.

Thanks for your help.

B
 
All you need to do is add a "dummy" node. That node will ensure that the
GUI shows the expand "+". Then when you get an expand event you check and
if the only node existing is the "dummy" node then you delete the "dummy"
node and then populate the expanded node. If there are no items to be
populated your user will see an empty tree node.

Easy to do and will make you app much faster.

Lloyd Sheen
 
Back
Top