PDA

View Full Version : Gtk::Table get cell value at x, y



froggyswamp
June 17th, 2009, 07:50 PM
Folks,
in Java I had a JTable where to get the value of a given cell I just wrote:
Object value = jtable.getValueAt(x, y);
and that's it.
But there doesn't seem to be such a thing in Gtkmm..
Can anyone please show me a quick example?

Habbit
June 17th, 2009, 08:00 PM
Well, a Gtk::Table is not comparable to a javax.swing.JTable. Its more like a JPanel with a GridLayout (or maybe GridBagLayout, I'm not that experienced). Maybe you should be using Gtk::TreeView?

froggyswamp
June 17th, 2009, 08:03 PM
I'm sorry, I indeed have a Gtk::TreeView, I just called it "table" because I have to deal much with Java..
So how do I do it with a Gtk::TreeView?

simeon87
June 17th, 2009, 08:21 PM
Edit: nevermind, I had posted some Python code for x,y as mouse coordinates but you appear to be looking for row/column coordinates.

froggyswamp
June 17th, 2009, 09:00 PM
uh... found out.. finally.. not as easy as in Java tough.



//DetailedTreeView extends Gtk::TreeView
bool DetailedTreeView::on_button_press_event(GdkEventBu tton* event) {

Gtk::TreeModel::Path path;
bool found = get_path_at_pos(event->x, event->y, path);

if(!found) {
return true;
}

Glib::RefPtr<Gtk::TreeModel> model = get_model();
Gtk::TreeModel::iterator iter = model->get_iter(path);
Gtk::TreeModel::Row row = *iter;
Glib::ustring sValue = row[treeModelCR.colName];//that's it..
}