views:

200

answers:

1

I have a GTK/C++ program that uses a ScrolledWindow. I keep adding data to the list within the scrolled window, and I want to keep focus on the newest item. But I also want to allow the user to scroll through the data to select an old item. Is there a way to do this? I've looked everywhere but can't find anything.

+1  A: 

It's not quite clear to me what you mean by your question, but here's what I think you mean: when you add items to your list, they are added below the current visible portion of the list. So if you start out looking at the bottom of the list, then add a lot of items, you end up looking at the middle of the list. What you want is to scroll to the bottom of the list every time an item is added.

If that's correct, then just scroll the window to the bottom every time you add an item:

Gtk::Adjustment *adj = scrolled_window.get_vadjustment();
adj->set_value(adj->get_upper());
while(Gtk::Main::events_pending())
    Gtk::Main::iteration();
ptomato