picoe / Eto

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

TreeGridView.Invalidate doesn't work #44

Closed evgeny-k closed 12 years ago

evgeny-k commented 12 years ago

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
{
    int[] arr = new int[] { 5, 5 };
    TreeGridView tv;
    TreeGridItem it;

    void CreateItem(TreeGridItem aParent, string aBaseName, int aLevel)
    {
        var lName = "[" + aLevel + "]" + aBaseName;
        var lItem = new TreeGridItem(lName);
        lItem.Expanded = true;
        if (lName == "[1]Name1") { it = lItem; };
        aParent.Children.Add(lItem);
        if (aLevel < arr.Length)
            for (int i = 0; i < arr[aLevel]; i++)
                CreateItem(lItem, aBaseName + i.ToString(), aLevel + 1);
    }

    void CreateTree()
    {
        TreeGridItem lRoot = new TreeGridItem();
        CreateItem(lRoot, "Name", 0);

        Application.Instance.Invoke(delegate
        {
            tv.DataStore = lRoot;
        });
    }

    public MainForm()
    {
        Size = new Size(900, 800);
        var lp = new Panel();
        this.AddDockedControl(lp, new Padding(5));
        var lPanelLayout = new TableLayout(lp, 1, 2);
        lPanelLayout.Padding = new Padding(0);
        var lButton = new Button();
        lButton.Text = "Select Item";
        lButton.Click += but_Click;

        lPanelLayout.Add(lButton, 0, 0);

        tv = new TreeGridView();
        tv.Columns.Add(new GridColumn { DataCell = new TextBoxCell(0) });
        lPanelLayout.Add(tv, 0, 1, true, true);
        CreateTree();
    }

    void but_Click(object sender, EventArgs e)
    {
        MessageBox.Show( "'"+it.Values[0]+"' item will be renamed to 'test'");
        it.Values[0] = "test";
        tv.Invalidate();           
    }
}

}

Note: probably this code should work without tv.Invalidate()

cwensley commented 12 years ago

Thanks again for the detailed test cases!