picoe / Eto

Cross platform GUI framework for desktop and mobile applications in .NET
Other
3.57k stars 325 forks source link

new TreeGridView has wrong level items #33

Closed carlokok closed 12 years ago

carlokok commented 12 years ago

Using the code below creates a tree like: http://i.imgur.com/2P7XL.png

which has level1 and level2 items between level3 (which shouldn't be possible with this logic)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Eto;
using Eto.Forms;
using Eto.Drawing;
using System.Threading;

namespace etotest
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            var generator = Generator.GetGenerator("Eto.Platform.Wpf.Generator, Eto.Platform.Wpf");

            var app = new TestApplication(generator);
            app.Run(args);
        }
    }

    public class TestApplication : Application
    {
        public TestApplication(Generator generator)
            : base(generator)
        {
            this.Name = "Test Application";
        }

        public override void OnInitialized(EventArgs e)
        {
            this.MainForm = new MainForm();
            HandleEvent(Application.TerminatingEvent);

            base.OnInitialized(e);

            // show the main form
            this.MainForm.Show();
        }

    }

    public class MainForm : Form
    {
        TreeGridView tv;

        TreeGridItem CreateTree()
        {
            Random rv = new Random();
            TreeGridItem res = new TreeGridItem("root");
            for (int i = 0; i < 1000; i++)
            {
                var item = new TreeGridItem( "level1_"+i);
                item.Expanded = true;
                res.Children.Add(item);

                for (int j = 0; j < 15; j++)
                {
                    var lItem = new TreeGridItem(Enumerable.Range(0, rv.Next(0, 100)).Select(a => new TreeGridItem("level3_" + a)), "level2_" + j);
                    item.Children.Add(lItem);
                    lItem.Expanded = true;
                }
            }
            return res;
        }

        public MainForm()
        {
            this.Title = "Test Application";
            this.Style = "main";
            this.ClientSize = new Size(900, 650);

            tv = new TreeGridView();
            var col = new GridColumn { DataCell = new TextBoxCell(0) };
            tv.Columns.Add(col);

            this.AddDockedControl(tv);
            var tree = CreateTree();
            tv.DataStore = tree;
            tv.Expanding += Expanding;
        }
        int expanding; 
        void Expanding(object o, EventArgs e)
        {
            expanding++;
            Title = "Expanded " + expanding;
        }
    }
}
cwensley commented 12 years ago

Thanks for the repro! It helped tremendously.