Grouping in TreeListView c#

409 views Asked by At

I use the component TreeListView from ObjectListView by Phillip Piper.

I want tree view with groups, but groups do not creating.

Somebody can me help with it?

I want it:

|        Column 1       | Column 2 | Column 3 |

== Group 1 [2 items] ===========================
   + Item 1             | Value 1  | Value 2  |
     Item 2             | Value 1  | Value 2  |
   - Item 3             | Value 1  | Value 2  |
       Sub Item 1       | Value 1  | Value 2  |
       Sub Item 2       | Value 1  | Value 2  |

== Group 2 [N items] ===========================
   + Item 1             | Value 1  | Value 2  |
   ...

UPDATE:

My model

public class Model
{
    public string Name { get; set; }
    public string Type { get; set; }
    public int[] Items { get; set; }
}

Gettter for get aspect foreach row object

olvColumnName.AspectGetter = delegate (object rowObject)
{
    if (rowObject is Model model)
        return model.Name;
    else if (rowObject is int numb)
        return numb.ToString();
    return null;
}

Group key getter

olvColumnType.GroupKeyGetter = delegate (object rowObject)
{
    if (rowObject is Model model)
        return model.Type;
    return null;
}

Check expand

treeListView1.CanExpandGetter = delegate (object rowObject)
{
    if (rowObject is Model model)
        return model.Items != null && model.Items.Length > 0;
    return false;
};

Get expand children

treeListView1.ChildrenGetter = delegate (object rowObject)
{
   if (rowObject is Model model)
      return model.Items;
   return null;
};

UPDATE:

I found that for the TreeListView component not defined GroupingStrategy property and did override CanShowGroups property which always return false.

So i think the component has properties, inherit from ObjectListView, but it not use they, and this mode not support.

0

There are 0 answers