Re: TreeView - First element
- From: Daniel Elstner <daniel kitta googlemail com>
- To: "Adam Chyla [PL]" <adam chyla gmail com>
- Cc: gtkmm-list gnome org
- Subject: Re: TreeView - First element
- Date: Tue, 05 Jan 2010 15:48:30 +0100
Hi,
Am Dienstag, den 05.01.2010, 05:44 -0800 schrieb Adam Chyla [PL]:
> It should works.
>
> Try this: http://chyla.site90.net/gtk_foobar-0.1.tar.gz
You were simply not testing whether the position after the selected item
is actually valid. The corrected code is attached.
Note that I used operator bool() instead of comparing against the end()
iterator, but I did so only for convenience. Either way works.
Cheers,
--Daniel
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
* main.cc
* Copyright (C) Adam Chyła 2010 <adam chyla gmail com>
*
* gtk-foobar is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* gtk-foobar is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Main.h"
MainClass::MainClass()
{
set_title("Hi all!");
set_default_size(400, 400);
add(MainVBox);
MainVBox.pack_start(MoveDown, Gtk::PACK_SHRINK);
MainVBox.pack_start(TreeViewExample);
MoveDown.set_label("MoveDown");
MoveDown.signal_clicked().connect(sigc::mem_fun(*this, &MainClass::MoveDownFun));
ListStore = Gtk::ListStore::create(Column);
TreeViewExample.set_model(ListStore);
row = *(ListStore->append());
row[Column.first] = "asdf";
row = *(ListStore->append());
row[Column.first] = "sdcsdcsdcsdcsd";
TreeViewExample.append_column("First", Column.first);
show_all_children();
}
MainClass::~MainClass()
{
}
void MainClass::MoveDownFun()
{
Glib::RefPtr<Gtk::TreeSelection> selection = TreeViewExample.get_selection();
Gtk::TreeModel::iterator iter = selection->get_selected();
if (iter)
{
Gtk::TreeModel::iterator next = iter;
if (++next)
ListStore->iter_swap(iter, next);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]