Hi! It's my first post here, I'll try to give all the information I think is useful so that anyone wanting to help me won't have it difficult! If I don't, please, ask for it, I may have been just not too smart to post that information.
The thing is I have a GtkWindow, inside it, there's a GtkVBox, and inside the box, a table full of buttons, and a GtkScrolledWindow with a GtkTreeViewInside. So I have a window with buttons and a GtkTreeView (of a GtkTreeStore).
I want to know in some of the callback functions of these buttons which row is selected (selection has been set to GTK_SELECTION_BROWSE, so one will almost always be selected). So, in my callback function I have:
Code:
orderViewGetter *getter=orderViewGetter::getInstance();
GtkTreeView *view=GTK_TREE_VIEW(getter->getView());
switch(id) //This is an enum, used to know which button was pressed
{
...
case EDIT_ORDER:
{//I put those brackets after compiler scolded me about scope
string selectedName;
GtkTreeModel *model;
GtkTreeSelection *selection=gtk_tree_view_get_selection(view);
GtkTreeIter iter;
if(gtk_tree_selection_get_selected(selection, &model, &iter))
{
//Column's number is PETS, a value from an enum
gtk_tree_model_get(model, &iter, PETS, &selectedName, -1);
cout << selectedName;
}
else
{
cout << "No selection " << endl;
}
}
break;
...
}
I get no errors of the compiler, nor runtime errors when I click the button, it just prints "No selection ". At first I hadn't put that "if" clause, and some errors appeared because that iterator wasn't valid.
I thought that the selected row might had been de-selected by clicking the buttons, so I disabled
them getting focus on click, but that didn't have any effect, just a more stylish click.
By the way, if that can help, I'm compiling with MinGW g++ and mingw32-make, in Window 7, using GTK 2.24. If you spot anything about style that might improve my coding, I will thank you for telling too :)
I hope you can help me, thanks in advance.