0
votes

I have a simple treeview (like this one - http://www.mono-project.com/GtkSharp_TreeView_Tutorial) filled with 200 items and connected to scrollbar. Everything works, but when I select an item and use arrow keys, selected item can be out of visible area. Is it possible to focus on it or set adjustment of scrollbar, i.e.

void HandleTreeSelectionChanged (object sender, EventArgs e)
{
    vadjustment.Value=SELECTED-ITEM.DISTANCE-FROM-TOP-OF-TREEVIEW;
}

And one more question: How to paint a black border to table (this tree.EnableGridLines = TreeViewGridLines.Both; makes just inside grid). Thanks in advance. Matej

2

2 Answers

0
votes

I agree with Johannes' answer that you seem to be doing something odd, you really should just need to use a GtkScrolledWindow. It should handle keyboard navigation (what you seem to be describing in your comment to Johannes' answer) too, this is not something you should need to be doing manually.

To anyway try to answer your question, you can cause the tree view to scroll to any given cell using gtk_tree_view_scroll_to_cell().

0
votes

To add scroll bars to a tree view (or text view), you just need to add it to a GtkScrolledWindow; it handles everything automatically. I'm pretty sure it also creates a border in most themes.

Update: Alternatively, you can also "bind" the tree view's scrolling behaviour to an arbitrary scrollbar by setting the scrollbar's adjustment to that of the tree view:

scrollbar = gtk.VScrollbar(treeview.props.vadjustment)

(Oh, that's the PyGTK syntax; in Gtk# it's probably treeview.VAdjustment.)