0

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

gpoo
  • 8,408
  • 3
  • 38
  • 53
matej148
  • 155
  • 1
  • 13

2 Answers2

0

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.)

Johannes Sasongko
  • 4,178
  • 23
  • 34
  • Sorry, but I need to have it separate. I need to know how to follow selected item (when user pushed down arrow key a I should add some number to vadjustment.Value and when pushed up arrow key, I should remove some number from vadjustment.Value). Thanks in advance. – matej148 Apr 10 '12 at 11:37
  • Thank you, but I have treeview connected to scrollbar, it works well. I just need to change VAdjustment when user change selected item - problem is that I do not know what is the value I have to add or remove to this: `vadjustment.Value=SELECTED-ITEM.DISTANCE-FROM-TOP-OF-TREEVIEW;` or `vadjustment.value += something` (when user push down arrow key) and `vadjustment.value -= something` (when user push up arrow key) – matej148 Apr 13 '12 at 21:19
0

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().

Community
  • 1
  • 1
unwind
  • 391,730
  • 64
  • 469
  • 606
  • Thank you for your answer, but ScrollToCell function doesn't work for me, because I have scrollbar and treeview separated (I have just tried it). It is connected in the table: layout.Put(tree, 0, 0); Table table = new Table(1, 2, false); table.Attach(layout, 0, 1, 0, 1, Gtk.AttachOptions.Expand|Gtk.AttachOptions.Fill, Gtk.AttachOptions.Expand|Gtk.AttachOptions.Fill, 0, 0); table.Attach(vscrollbar, 1, 2, 0, 1, Gtk.AttachOptions.Shrink, Gtk.AttachOptions.Shrink|Gtk.AttachOptions.Fill, 0, 0); and I catch event (row select) with tree.Selection.Changed+=HandleTreeSelectionChanged; – matej148 Apr 10 '12 at 14:50