0

I have an item list and I want to put a text input:

enter image description here

enter image description here

using Gtk;

public class TreeViewSample : Window {

    public TreeViewSample () {
        this.title = "Programa de odontologia";
        set_default_size (500,500);
        var view = new TreeView ();
        setup_treeview (view);
        add (view);
        this.destroy.connect (Gtk.main_quit);
    // The Entry:
        Gtk.Entry entry = new Gtk.Entry ();
        this.add (entry);

        // Add a default-text:
        entry.set_text ("hello, world!");

        // Add a delete-button:
        entry.set_icon_from_icon_name (Gtk.EntryIconPosition.SECONDARY, "edit-clear");
        entry.icon_press.connect ((pos, event) => {
            if (pos == Gtk.EntryIconPosition.SECONDARY) {
                entry.set_text ("");
            }
        });

        // Print text to stdout on enter:
        entry.activate.connect (() => {
            unowned string str = entry.get_text ();
            stdout.printf ("%s\n", str);
        });
}

    private void setup_treeview (TreeView view) {

        /*
         * Use ListStore to hold accountname, accounttype, balance and
         * color attribute. For more info on how TreeView works take a
         * look at the GTK+ API.
         */

        var listmodel = new ListStore (5, typeof (string), typeof (string),
                                          typeof (string), typeof (string), typeof (string));
        view.set_model (listmodel);

        view.insert_column_with_attributes (-1, "Nombre del paciente", new CellRendererText (), "text", 0);
        view.insert_column_with_attributes (-1, "Apellido", new CellRendererText (), "text", 1);
    view.insert_column_with_attributes (-1, "Tratamiento", new CellRendererText (), "text", 2);

        var cell = new CellRendererText ();
        cell.set ("foreground_set", true);
        view.insert_column_with_attributes (-1, "Lo que debe", cell, "text", 3, "foreground", 4);


        TreeIter iter;
        listmodel.append (out iter);
        listmodel.set (iter, 0, "Agustin", 1, "Gomez", 3, "0", 2, "conducto", 4, "blue");

        listmodel.append (out iter);
        listmodel.set (iter, 0, "Laura", 1, "Gomez", 3, "$100", 2, "conducto", 4, "red");

    listmodel.append (out iter);
        listmodel.set (iter, 0, "Luis", 1, "Gomez", 3, "$400", 2, "conducto", 4, "green");
    }

    public static int main (string[] args) {
        Gtk.init (ref args);

        var sample = new TreeViewSample ();
        sample.show_all ();
        Gtk.main ();

        return 0;
    }
}
1

Sounds like you want Gtk.Overlay.

That said, a better design would probably be to put both the Gtk.TreeView and Gtk.Entry an a Gtk.Box so the entry doesn't occlude the tree view…

  • I need more help please, im a beginner , i only know C programming, can you give me an example of Gtk.Overlay. Or how to use the Gtk.treeView , Gtk.Entry and Gtk.Box, its not necesary to follow my example, i need a simple explanation Thanks nemequ – Agu Nunes Mar 13 '16 at 6:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.