Eto TreeGridView cell order issue on scrolling

I use Eto’s TreeGridView and display a single column that uses Eto’s CustomCell. This seems to render correctly until the tree is large enough so that it gets a scroll bar. Once I start scrolling to view the tree, the cells can be rendered in a different order than they exist in the DataStore.

Example:
I created a tree to display two different types of Nodes, A and B. The tree’s datastore is initialized:

public class Root : ITreeGridStore<Node>, ITreeGridItem
{
    List<Node> nodes;
    public Root()
    {
        nodes = new List<Node>();
        for (int i = 0; i < 10; i++)
        {
            nodes.Add(new NodeA(this));
            nodes.Add(new NodeA(this));
            nodes.Add(new NodeB(this));
            nodes.Add(new NodeB(this));
        }
    } 

where the column is set up to display the cell via:

column = new GridColumn
        {
            AutoSize = true,
            Editable = true,
            Resizable = false,
            Sortable = false,
            DataCell = new CustomCell
            {
                CreateCell = (args) => (args.Item as Node).CreateCell(args),
                ConfigureCell = (args, control) => { control.DataContext = args.Item; }
            }

and where the create cell functions are:

public class NodeA : Node
{
    public NodeA(ITreeGridItem p) : base(p) { }
    public override Control CreateCell(CellEventArgs a)
    {
        return new Label { Text = "A  A  A", BackgroundColor = Colors.Blue };
    }
}
public class NodeB : Node 
{
    public NodeB(ITreeGridItem p) : base(p) { }
    public override Control CreateCell(CellEventArgs a)
    {
        return new Label { Text = "B  B  B", BackgroundColor = Colors.Yellow };
    }
}

This shows how the cells can be created/?displayed in a different order than the datastore when the tree is scrolled up and down:

Is there a way to prevent this issue?

Code:
EtoTreeGridViewDemo1.zip (93.6 KB)

Hi @jakemurphy0118,

The problem you are having is because cells are reused, and you are not configuring the cell properly. During your ConfigureCell, you need to change the properties of the existing control (which is passed in as a parameter) to match the new args.Item.

Note that setting the DataContext only works if you are using MVVM bindings with your controls.

Hope this helps!