Re: Selecting rows automatically...



2009/6/8 Sever P A <gnu sever gmail com>:
> Hello,
>
> In order to improve my app. and understand better the Gtk::TreeView
> and so (I use a Gtk::ListStore as a TreeModel), I'm trying to select
> rows automatically. For this, I have an int variable that stores an
> index pointer. I know that iterators serve to this kind of needs...
> but here I'm really confused.
>
> How can I manage this int (entire) value to select an associated row ?

TreeModel (http://www.gtkmm.org/docs/gtkmm-2.4/docs/reference/html/classGtk_1_1TreeModel.html)
has a children() method which has a [] operator. Thus, you can do
something like:

    Glib::RefPtr<Gtk::ListStore> data = Gtk::ListStore::create(columns);

    Gtk::TreePath path(data->children()[selectedItemIndex]);
    view.set_cursor(path);
    view.scroll_to_row(path);

or:

    Glib::RefPtr<Gtk::ListStore> data = Gtk::ListStore::create(columns);
    Gtk::TreeModel::Children children = data->children();
    for (std::vector<int>::const_iterator first = children.begin(),
last = children.end(); first != last; ++first)
    {
        Gtk::TreePath path(first);
        view.set_cursor(path); // not sure if multi-select is supported
    }

NOTE: I haven't tested either of the examples, and you'd probably need
to check if the iterator and/or path are valid first.

HTH,
- Reece


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]