Article

How to use recursive data relation with UltraTree

« Go Back

Information

 
EnvironmentWindows
OpenEdge 10.2x
Question/Problem Description
How to use recursive data relation with UltraTree
How to display recursive data in UltraTree component
Clarifying Information
Error Message
Defect/Enhancement Number
Cause
Resolution

There are a couple things to remember in order for this to work seamlessly.  An example is provided below that follows these bulleted points:

1) The actual organization of the data for display in the tree is performed during the DATASET's FILL operation; therefore the dataset that is used to feed the tree MUST be filled from some source.  The example demonstrates filling this from a dummy temp-table

2) The query must be filtered on the TOP level or ROOT node

/* Sample */
USING System.Windows.Forms.*.
USING Infragistics.Win.UltraWinGrid.*.

DEFINE VARIABLE oMainForm      AS System.Windows.Forms.Form                      NO-UNDO.
DEFINE VARIABLE oTree          AS Infragistics.Win.UltraWinTree.UltraTree        NO-UNDO.
DEFINE VARIABLE oBindingSource AS Progress.Data.BindingSource                    NO-UNDO.
DEFINE VARIABLE oDrawPt1       AS System.Drawing.Point                           NO-UNDO.
DEFINE VARIABLE oDrawPt2       AS System.Drawing.Point                           NO-UNDO.
DEFINE VARIABLE oDrawSz1       AS System.Drawing.Size                            NO-UNDO.
DEFINE VARIABLE oControls      AS System.Windows.Forms.Control+ControlCollection NO-UNDO.

DEFINE VARIABLE oTopNavQry     AS HANDLE      /* nav query for customer */       NO-UNDO.
DEFINE VARIABLE hDataset       AS HANDLE                                         NO-UNDO.

/* Fake out Data Source */
DEFINE TEMP-TABLE ttDummyEmp NO-UNDO
    FIELD tcEmpName AS CHARACTER
    FIELD tcManager AS CHARACTER
    FIELD tiAge AS INTEGER
    FIELD tcDeptName AS CHARACTER
    INDEX idxEmpName AS UNIQUE tcEmpName.

/* DEFINE A DATASET */
DEFINE TEMP-TABLE ttEmp NO-UNDO
    FIELD tcEmpName AS CHARACTER
    FIELD tcManager AS CHARACTER
    FIELD tiAge AS INTEGER
    FIELD tcDeptName AS CHARACTER
    INDEX idxEmpName AS UNIQUE tcEmpName.

                       
DEFINE DATASET myrecurs FOR ttEmp
    DATA-RELATION r1 FOR ttEmp,ttEmp
                RELATION-FIELDS(tcEmpName,tcManager) RECURSIVE.

DEFINE QUERY qDummy FOR ttDummyEmp.
DEFINE DATA-SOURCE srcDummy FOR QUERY qDummy.

/* Fake out datasource records */
CREATE ttDummyEmp.
ttDummyEmp.tcEmpName = "niel".

CREATE ttDummyEmp.
ASSIGN ttDummyEmp.tcEmpName = "dave"
       ttDummyEmp.tcManager = "niel".
      
CREATE ttDum.myEmp.
ASSIGN ttDummyEmp.tcEmpName = "ken"
       ttDummyEmp.tcManager = "niel".
      
CREATE ttDummyEmp.
ASSIGN ttDummyEmp.tcEmpName = "peter"
       ttDummyEmp.tcManager = "niel".
      
CREATE ttDummyEmp.
ASSIGN ttDummyEmp.tcEmpName = "martha"
       ttDummyEmp.tcManager = "peter".
      
CREATE ttDummyEmp.
ASSIGN ttDummyEmp.tcEmpName = "evan"
       ttDummyEmp.tcManager = "martha".
      
CREATE ttDummyEmp.
ASSIGN ttDummyEmp.tcEmpName = "robin"
       ttDummyEmp.tcManager = "evan".
      
CREATE ttDummyEmp.
ASSIGN ttDummyEmp.tcEmpName = "rich"
       ttDummyEmp.tcManager = "evan".
      
CREATE ttDummyEmp.
ASSIGN ttDummyEmp.tcEmpName = "robert"
       ttDummyEmp.tcManager = "martha".
      
CREATE ttDummyEmp.
ASSIGN ttDummyEmp.tcEmpName = "shelley"
       ttDummyEmp.tcManager = "martha".
      
CREATE ttDummyEmp.
ASSIGN ttDummyEmp.tcEmpName = "mary"
       ttDummyEmp.tcManager = "ken".
      
CREATE ttDummyEmp.
ASSIGN ttDummyEmp.tcEmpName = "alex"
       ttDummyEmp.tcManager = "robert".
      
CREATE ttDummyEmp.
ASSIGN ttDummyEmp.tcEmpName = "jane"
       ttDummyEmp.tcManager = "robert".
      
CREATE ttDummyEmp.
ASSIGN ttDummyEmp.tcEmpName = "sue"
       ttDummyEmp.tcManager = "robert".

BUFFER ttEmp:ATTACH-DATA-SOURCE(DATA-SOURCE srcDummy:Handle).
QUERY qDummy:QUERY-PREPARE("for each ttDummyEmp where tcEmpName = 'niel' ").

DATASET myrecurs:FILL().

DO ON ERROR UNDO, LEAVE:
  oMainForm = NEW System.Windows.Forms.Form().
  oTree = NEW Infragistics.Win.UltraWinTree.UltraTree().

  oDrawPt1 = NEW System.Drawing.Point(0,0).
  oDrawPt2 = NEW System.Drawing.Point(0,0).
  oDrawSz1 = NEW System.Drawing.Size(oDrawPt1).
      
  oDrawSz1:Width = 680.
  oDrawSz1:Height = 480.
  oMainForm:ClientSize = oDrawSz1.

  oDrawPt1:X = 16.
  oDrawPt1:Y = 16.
  oTree:Location = oDrawPt1.
  oTree:TabIndex = 9.
  oDrawSz1:Width = 620.
  oDrawSz1:Height = 424.
  oTree:Size = oDrawSz1.

  oControls = oMainForm:controls.
  oControls:Add(oTree).
   
  hDataset = DATASET myrecurs:HANDLE.

  oTopNavQry = hDataset:TOP-NAV-QUERY(1).
  oTopNavQry:QUERY-PREPARE("preselect each ttEmp where tcEmpName = 'niel' ").
  oTopNavQry:QUERY-OPEN(). 
  
  oBindingSource = NEW Progress.Data.BindingSource(hDataset). 
  oTree:DataSource = oBindingSource.

  WAIT-FOR Application:Run(oMainForm).

  RUN cleanup.
END.

PROCEDURE cleanup:

    IF VALID-OBJECT(oBindingSource) THEN DO:
        oBindingSource:Dispose().
    END.

    REPEAT WHILE SESSION:FIRST-OBJECT <> ?:
        DELETE OBJECT(SESSION:FIRST-OBJECT).
    END.
END.
 

.myEmp.
ASSIGN ttDummyEmp.tcEmpName = "ken"
       ttDummyEmp.tcManager = "niel".
      
CREATE ttDummyEmp.
ASSIGN ttDummyEmp.tcEmpName = "peter"
       ttDummyEmp.tcManager = "niel".
      
CREATE ttDummyEmp.
ASSIGN ttDummyEmp.tcEmpName = "martha"
       ttDummyEmp.tcManager = "peter".
      
CREATE ttDummyEmp.
ASSIGN ttDummyEmp.tcEmpName = "evan"
       ttDummyEmp.tcManager = "martha".
      
CREATE ttDummyEmp.
ASSIGN ttDummyEmp.tcEmpName = "robin"
       ttDummyEmp.tcManager = "evan".
      
CREATE ttDummyEmp.
ASSIGN ttDummyEmp.tcEmpName = "rich"
       ttDummyEmp.tcManager = "evan".
      
CREATE ttDummyEmp.
ASSIGN ttDummyEmp.tcEmpName = "robert"
       ttDummyEmp.tcManager = "martha".
      
CREATE ttDummyEmp.
ASSIGN ttDummyEmp.tcEmpName = "shelley"
       ttDummyEmp.tcManager = "martha".
      
CREATE ttDummyEmp.
ASSIGN ttDummyEmp.tcEmpName = "mary"
       ttDummyEmp.tcManager = "ken".
      
CREATE ttDummyEmp.
ASSIGN ttDummyEmp.tcEmpName = "alex"
       ttDummyEmp.tcManager = "robert".
      
CREATE ttDummyEmp.
ASSIGN ttDummyEmp.tcEmpName = "jane"
       ttDummyEmp.tcManager = "robert".
      
CREATE ttDummyEmp.
ASSIGN ttDummyEmp.tcEmpName = "sue"
       ttDummyEmp.tcManager = "robert".

BUFFER ttEmp:ATTACH-DATA-SOURCE(DATA-SOURCE srcDummy:Handle).
QUERY qDummy:QUERY-PREPARE("for each ttDummyEmp where tcEmpName = 'niel' ").

DATASET myrecurs:FILL().

DO ON ERROR UNDO, LEAVE:
  oMainForm = NEW System.Windows.Forms.Form().
  oTree = NEW Infragistics.Win.UltraWinTree.UltraTree().

  oDrawPt1 = NEW System.Drawing.Point(0,0).
  oDrawPt2 = NEW System.Drawing.Point(0,0).
  oDrawSz1 = NEW System.Drawing.Size(oDrawPt1).
      
  oDrawSz1:Width = 680.
  oDrawSz1:Height = 480.
  oMainForm:ClientSize = oDrawSz1.

  oDrawPt1:X = 16.
  oDrawPt1:Y = 16.
  oTree:Location = oDrawPt1.
  oTree:TabIndex = 9.
  oDrawSz1:Width = 620.
  oDrawSz1:Height = 424.
  oTree:Size = oDrawSz1.

  oControls = oMainForm:controls.
  oControls:Add(oTree).
   
  hDataset = DATASET myrecurs:HANDLE.

  oTopNavQry = hDataset:TOP-NAV-QUERY(1).
  oTopNavQry:QUERY-PREPARE("preselect each ttEmp where tcEmpName = 'niel' ").
  oTopNavQry:QUERY-OPEN(). 
  
  oBindingSource = NEW Progress.Data.BindingSource(hDataset). 
  oTree:DataSource = oBindingSource.

  WAIT-FOR Application:Run(oMainForm).

  RUN cleanup.
END.

PROCEDURE cleanup:

    IF VALID-OBJECT(oBindingSource) THEN DO:
        oBindingSource:Dispose().
    END.

    REPEAT WHILE SESSION:FIRST-OBJECT <> ?:
        DELETE OBJECT(SESSION:FIRST-OBJECT).
    END.
END.
 

.
Workaround
Notes
Attachment 
Feedback
 
Was this article helpful?

   

Your feedback is appreciated.

Please tell us how we can make this article more useful.



Characters Remaining: 255

 



Copyright © 1993-2014. Progress Software Corporation. All Rights Reserved. See the next generation of application development and data connectivity software, try now!