Marc
  • Marc
  • Member Topic Starter
2013-03-21T10:43:08Z
Hi Igor, hi everybody,

I have a grid containing hierarchical structures, e.g. a contact list like shown below:


Column "NAME"             Column "REVENUE"

Company A                 140
   |__ Department 1        90
         |__ Person NN     60
         |__ Person LL     30
   |__ Department 2        50
         |__ Person XY     50
Company B                 200


If I use the sort function on column "REVENUE", iGrid switches positions of persons "NN" and "LL".
Everthing fine so far.

Sometimes it would be nice to:
a) switch between a hierarchical (tree) view and a flat view of the same data
b) have the grid ordered by "REVENUE" without considering the persons' parent/child relationship.

Is there an easy way to switch between a tree view and a flat view without rebuilding the grid (i.e. reload data without parent/child relationship)?
If yes, is it possibly to apply the sort function to the whole set of data without considering existing parent/child relationship?

Expected result:

Column "NAME"             Column "REVENUE"

Person LL                  30
Department 2               50
Person XY                  50
Person NN                  60
Department 1               90
Company A                 140
Company B                 200


I have tried to set TreeCol="some hidden column" which works fine to display the "NAME" column flat. But of course, this does not affect the sort behaviour.

Thank you for shareing your thoughts on that question!

Kind regards,
Marc
Igor/10Tec
2013-03-22T09:43:10Z
It's a very good question - appreciate it. I'm gonna even to move it to the KB section.

When iGrid has a tree and hierarchical data (non-zero RowLevel's), it sorts its data using the node relationships automatically. That's normal behavior. To convert it to flat view, you just need to remove the info about hierarchy - just reset the RowLevel/RowTreeButton properties.

But if you wish to SWITCH between tree and flat view, you need to store the original relationships somewhere. Below is an example of such a sub in which I imply we use the special hidden 4th, 5th and 6th columns to store the original tree structure:

Private Sub FlatView()
   With iGrid1
      .BeginUpdate
      
      .TreeCol = 0
      
      Dim iRow As Long
      For iRow = 1 To .RowCount
         .CellValue(iRow, 4) = .RowLevel(iRow)
         .RowLevel(iRow) = 0
         .CellValue(iRow, 5) = .RowTreeButton(iRow)
         .RowTreeButton(iRow) = igRowTreeButtonAbsent
         .CellValue(iRow, 6) = iRow
      Next
      
      .EndUpdate
   End With
End Sub


To restore the original tree look, use a sub like the following:

Private Sub TreeView()
   With iGrid1
      .BeginUpdate
      
      .TreeCol = 1
      
      .SortObject.Clear
      .SortObject.AddItem 6
      .Sort
      
      Dim iRow As Long
      For iRow = 1 To .RowCount
         .RowLevel(iRow) = .CellValue(iRow, 4)
         .RowTreeButton(iRow) = .CellValue(iRow, 5)
      Next
      
      .EndUpdate
   End With
End Sub


Pay attention to the fact that we store the original row order. If we do not do that and simply restore RowLevel/RowTreeButton, it's not right in the general case as the tree structure (node order) may be already corrupted after sorting in flat view.

Have I missed something?
Marc
  • Marc
  • Member Topic Starter
2013-03-22T17:06:44Z
Thanks a lot. That is exactly what I am looking for!

Regards,
Marc