Menu

Get OLV items in "tree sort order"

2015-04-08
2015-04-10
  • Bernhard Mayer

    Bernhard Mayer - 2015-04-08

    Dear fellow OLV'ers!

    Does anybody know a way how to get the items of a DataTreeListView in the "tree sort order"?

    Sample: Imagine a DataTreeListView has the following data source (KeyAspectName = ID, ParentKeyAspectName = ParentID).

    Item A with ParentID 0 has ID 1
    - Item D with ParentID 1 + ID 5
    - Item E with ParentID 1 + ID 6
    Item B with ParentID 0 hast ID 2
    - Item C with ParentID 2 + ID 3
    - Item D with ParentID 2 + ID 4

    I would like to get a list containing the items A, D, E, B, C, D in this sort order; is there already a property which will return this data?

    TIA,
    Bernhard

     
  • CFrank

    CFrank - 2015-04-09

    Hi Bernhard,

    more or less.
    What about calling Select.All and iterating over SelectedObjects?
    Something like (VB.Net)

    Me.TreeListView.SelectAll()
    For Each obj In Me.TreeListView.SelectedObjects
        Debug.Print(String.Format("{0}",obj))
    Next
    

    Cheers
    Claudia

     
  • Phillip Piper

    Phillip Piper - 2015-04-09

    You could also use GetNthItemInDisplayOrder().

    This utility method will work with any type of ObjectListView, grouped or ungrouped:

    public IEnumerable GetModelObjectsInDisplayOrder(ObjectListView olv) {
        if (olv == null)
            yield break;
    
        for (int i = 0; i < olv.GetItemCount(); i++) {
            OLVListItem olvItem = olv.GetNthItemInDisplayOrder(i);
            if (olvItem != null)
                yield return olvItem.RowObject;
        }
    }
    
     
  • Bernhard Mayer

    Bernhard Mayer - 2015-04-10

    Very nice, thanks to you both.

     

Log in to post a comment.