On Friday, 20 November 2015 at 17:09:50 UTC, TheDGuy wrote:
Hello,

is it possible, to delete a selected TreeView SubItem with a Button-Click?

My Code currently looks like this:

import gtk.MainWindow;
import gtk.Box;
import gtk.Main;

import gtk.Button;
import gdk.Event;
import gtk.Widget;

import List, Languages;

void main(string[] args){
        Main.init(args);
        MainWindow win = new MainWindow("TreeView Example");
        win.setDefaultSize(500,300);

        Box box = new Box(Orientation.VERTICAL, 0);

        auto list =  new List();
        auto german = list.addCountry("German", "Germany");
        auto city = list.addCountryCity(german, "German", "Munich");

        auto sweden = list.addCountry("Swedish", "Sweden");
        auto cit = list.addCountryCity(sweden, "Swedish", "Stockholm");

        auto treeView = new LanguageTree(list);
        box.packStart(treeView, true, true, 0);

        auto btn_Delete = new Button("Delete");
        box.add(btn_Delete);

        win.add(box);
        win.showAll();
        Main.run();
}

class DeleteButton : Button
{
        this(in string text)
        {
                super(text);
                addOnButtonRelease(&del);
        }
        private bool del(Event event, Widget widget)
        {
                return true;
        }

}

But i neither know how i get the currently selected item nor how i could delete it within the "del"-Event of the "DeleteButton"?

TreeIter iter = treeView.getSelectedIter;

then you can use the TreeIter to delete the item.
If your List is a ListStore or TreeStore, it has a remove method that you can call. If its a custom store you will have to implement it yourself like this

class List:TreeModel
{
.....
        void remove(TreeIter iter)
        {
//maybe remove item from your actual data structure or other processing

                //send rowDeleted signal
                rowDeleted(iter);

        }
.....
}

Reply via email to