Re: Finding the column index for a Gtk::TreeViewColumn from a Gtk::TreeView



On Sun, 23 Apr 2006 19:24:33 +0200 Murray Cumming <murrayc murrayc com>
waved a wand and this message magically appeared:

> On Sun, 2006-04-23 at 13:12 -0400, Paul Davis wrote:
> > On Fri, 2006-04-21 at 20:15 +0100, Alex Buell wrote:
> > > Does anyone knows how I can find the column index for a given
> > > Gtk::TreeViewColumn from a Gtk::TreeView object? Thanks!
> > 
> > if you are talking about doing this from (for example) a button
> > event handler then suprisingly enough, you can't. the tutorial on
> > the treeview mentions this deficiency, which i find hard to
> > believe. i use the solution of using the set_data() method to store
> > a column index at construction time and get_data() to fetch it in
> > the event handler. it seems crude and i think that GTK+ should do
> > better on this one.
> 
> I guess you could iterate through the TreeViewColumns and do a pointer
> comparison, to discover the view model index.

Right I see. Perhaps I've been going about it in the wrong way. I am
writing a Sudoku application in gtkmm. I need to display a grid of 9x9
digits,  I use a TreeView model for that, but doesn't seem to work very
well at all. 

I wonder if any of you have ideas on how I can properly implement a 9x9
grid with digits in it (always 1 to 9). 

I currently define an array of nine integers per row like so:

        class ModelColumns : public Gtk::TreeModel::ColumnRecord
        {
        public:
                Gtk::TreeModelColumn<int> m_Item[9];

                ModelColumns()
                {
                        for (int i = 0; i < 9; i++)
                                add(m_Item[i]);
                }
        };

        ModelColumns m_Columns;

Then I just append nine rows of that to the TreeView. Doing this way
seems a bit tricky and that was why I needed to get the column
index. Now it seems to me that using arrays probably isn't the right way
because we don't know which column it is when my custom editable cell
validation routines are called. Trying to implement a helper routine to
get the column index only resulted in wierd things happening such as
having an entire column filled with the same number that I'd entered in
a cell in the same column!! ;)

Here's my helper routine:
int SudokuCreater::get_column_number()
{
        Gtk::TreePath Path;
        Gtk::TreeViewColumn *Column;
        m_TreeView.get_cursor(Path, Column);
        Glib::ListHandle<Gtk::TreeViewColumn*> Columns =
m_TreeView.get_columns();

        int num = 0;

        Glib::ListHandle<Gtk::TreeViewColumn*>::const_iterator i =
Columns.begin(); 
	do 
	{ 
		if (*i == Column)
                        break;

                num++, i++;
        }
        while (i != Columns.end());

        return num;
}

I'd be grateful for ideas on the best approach to use. Some of my
code is downright UGLY!

-- 
http://www.munted.org.uk

Take a nap, it saves lives.



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