[Gtk-sharp-list] Context Menu On A TreeView Row
Adam Tauno Williams
awilliam@whitemice.org
Wed, 29 Sep 2004 07:59:18 -0400
I am trying to build a popup menu attached to a click or popup event
(Shift F10) on items in a treeview. Does anyone have a Gtk#/C# example
for doing this? I've tried translating from an example in C but
apparently I've missed something.
1.) The ButtonPressEvent doesn't get fired when a row is clicked on,
although the row does become 'highlighted' normally.
2.) The PopUp event does fire, but no menu appears.
....
teamTreeView = new TreeView();
....
teamTreeView.PopupMenu += on_tree_popup_menu;
teamTreeView.ButtonPressEvent += on_tree_button_press;
....
}
public void on_tree_popup_menu(object o, PopupMenuArgs args)
{
Console.WriteLine("ComlaborareTeams:on_tree_popup_menu");
DoPopUp();
}
public void on_tree_button_press(object o, ButtonPressEventArgs args)
{
Console.WriteLine("ComlaborareTeams:on_tree_button_press");
if (args.Event.Button == 3)
{
DoPopUp();
}
}
protected void DoPopUp()
{
Menu popup = new Menu();
popup.Add(new MenuItem("Edit"));
popup.Add(new MenuItem("Remove"));
popup.Popup(null, null, null, IntPtr.Zero, 3,
Gtk.Global.CurrentEventTime);
}