Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
45
Showing two tables in the WinTree - Band nodes problem
posted

Background
I am trying to display two tables in an UltraTree control: Location and Machine.  The Location table is the hierarchy; the Machine table references the Location table.

The tables have the following columns (the relevant ones):
Location
--------
LocationPK
Name
ParentLocationPK

Machine
-------
MachineID
Name
LocationPK
(lots of other columns)

Each node in the tree will have one of two types of children - any number of locations *or* exactly 1 machine.

I want the tree to display the Location heirarchy using just the name column, and if they expand a name and it is referenced by a machine, show the machine details (quite a few columns of information).

Problem
Currently whenever a Location node is expanded, it shows two child nodes - "Location" and "Machine".  The user then has to expand the "Location" and "Machine" columns to see the next layer of details.

Is there a way to hide the "Location" and "Machine" nodes from appearing, and instead show their children, when only one of those bands has children? 

Edited to add:
From the documentation on the UltraTreeColumnSettings.ShowBandNodes, it says: "Regardless of the setting of ShowBandNode, band nodes will always be created to separate siblling bands. In a case where a child band has no siblings, a band node will be created for it if ShowBandNodes is set to ShowBandNodes.Always"

Obviously the UltraTree considers that there are two bands for each node - the Location and Machine bands.  However the business rule prevents this from ever happening.

Is there a way to hide a band from appearing when there are no child nodes for that band?

 

Example
I am seeing this:
- RootLocation
  - Location
    - ThisIsALocationName
    - AndAnother
      - Location
        - YetAnotherLocation
          - Location
          - Machine
            - AMachine | All | Columns | Appear | Here...
      - Machine
  - Machine

but want to see this instead:
- RootLocation
  - ThisIsALocationName
  - AndAnother
    - YetAnotherLocation
      - AMachine | All | Columns | Appear | Here...



Further Details
I have created a DataSet and populated it with two tables, Location and Machine.  I have added two relationships to the DataSet like so:


dataSet.Relations.Add("Location", rv.Tables["Location"].Columns["LocationPK"], rv.Tables["Location"].Columns["ParentLocationPK"], false);

dataSet.Relations.Add("Machine", rv.Tables["Location"].Columns["LocationPK"], rv.Tables["MachineColumns["LocationPK"], false);

 

I have looked through the examples in the WinTree folder in the Samples directory.  I have not been able to find an example that uses two tables in one tree via a bound DataSet.

We have also considered styling the screen after the sample in folder "DataBinding (Navigation) CS"; however we'd like to see if this specific problem can be overcome as we will most likely encounter this situation again in the future.

Parents
No Data
Reply
  • 469350
    Verified Answer
    Offline posted

    Hi Gavin,

    There's no way the tree can handle this for you automatically, but it's probably possible to do what you want with a little extra effort. 

    I am assuming that you are probably just leaving the tree with the default setting for AutoGenerateColumnSets and so the tree is creating two ColumnSets - one for the Location table and one for the Machine table. The Location table will have five columns. Three of these are the fields of the data. The other two are chaptered columns that represent the child bands - one for Location and one for Machine. 

    As long as both of these columns exist in the column set and they both have IsChaptered set to true, the tree has to show the two Band Nodes to separate the sibling bands. The IsChaptered property on the column is settable, but you don't really want to set it because that will affect every node in the tree, not just the ones where there are no child Locations. 

    So what you should be able to do is create a new ColumnSet which is an exact copy of the Locations ColumnSet but does not include the Locations column. Then you would need to examine each node in code and determine if it has no child locations and if it does not, you can assign this ColumnSet to that node - thus eliminating the Locations under that node. 

    There are a couple of caveats to this. First, you probably don't want to loop through every node in the tree. So I would recommend using the InitializeDataNode event. 

    Second, getting child rows for a particular node through the DotNet binding model can be an expensive operation. So if, in InitializeDataNode, you check for the existance of child nodes under the Location Band node, it might slow things down. It would probably be better for you to use the DataSource itself to determine if the parent row has any child rows rather than trying to get this information through the tree. You can use the node.ListObject to get the underlying data row for a partilcluar node in the tree. 

Children