views:

2240

answers:

1

Does anyone know of a way to represent a tree structure in Crystal Reports? My big issue is that I don't know the depth of the tree. It is represented in a database table with a simple "childId -> parentId" relationship.

A perfect example would be to open Windows Explorer, and look at the directory tree on the left side. If anyone knows a way to represent that tree, then it'll work for what I need to do too.

My initial attempts have been:

1) to programatically (in C#) add Groups to the report. Unfortunately, you can't create a new instance of the Group class and add it to the Groups collection.

2) recursively nest the same report into itself for each level. In other words:

mainReport
  subReport
    subReport
    subReport
  subReport
  subReport
    subReport

etc...

Unfortunately, SubReports can't contain SubReports.

I really don't want to just add X number of groups into a report and hide the ones I don't need, because I'd have to add a fixed number of nested groups, but technically the data design can support an infinite depth, even though in practice we see up to about 5 levels of depth.

So, any other ideas?

+2  A: 

Crystal XI added hierarchical grouping. You'll find this under the Reports menu. I put together a quick org chart report with n-level depth using this. The database table is like: id name managerId

In the Crystal Report, you select these columns, group by id. Then under "Hierarchical Grouping options" menu under Reports, check off "Group Data Hierarchically", parent Id managerId, and indent appropriately.

The output is like the tree you described in Explorer.

jons911
thanks! I'm not sure what version we are using, but it looks like its time to convince the boss its time to upgrade :) thanks again!
rally25rs
Good luck! I upgraded from 9 to XI; I for one will attest the upgrade is well worth it.
jons911