[Gtk-sharp-list] popup menu (combobox?) for treeview?

Andy York andy at brdstudio.net
Fri May 22 07:28:53 EDT 2009

Here is what worked well for me, if a more verbose example would help 
please feel free to ask. I didn't test this example but I'm pretty sure 
it's correct.

TreeView1.ButtonPressEvent += new 

private void TreeView1_ButtonPress(object o, Gtk.ButtonPressEventArgs args)
    // check if the right button was pushed
    if((int)args.Event.Button == 3)
        Gtk.Menu jBox = new Gtk.Menu();
        Gtk.MenuItem MenuItem1 = new MenuItem("new job");
        MenuItem1 = new MenuItem("edit job");
        MenuItem1 = new MenuItem("remove job");
        MenuItem1 = new MenuItem("remove finished jobs");

Spoody Goon

danieru wrote:
> Greetings!
> I'm trying to implement a popup menu for my treeview. From other threads
> I've found out how to capture the mouse right-click event with
> [Gtk.ConnectBeforeAttribute], so that's working ok. Now I'm unclear on how
> to make the correct type of menu and have it popup. I had found instructions
> in the Mono API documentation explaining how to use a menu class, add
> menuitems, etc., but that was a dead-end since it's telling you to use the
> obsolete OptionMenu. I then found another thread here saying to use a
> ComboBox instead, but the docs don't mention anything about how to use a
> ComboBox as a popup menu. I am seeing the Popup function, but can't seem to
> get it to work. I'm trying this:
> Gtk.ComboBox jBox = ComboBox.NewText();
> jBox.AppendText("new job");
> jBox.AppendText("edit job");
> jBox.AppendText("remove job");
> jBox.AppendText("remove finished jobs");
> jobsView.Add(jBox);
> jobsView.ShowAll();
> jBox.Popup();
> ...I'm fairly new to Gtk so am not clear on if the Add and ShowAll functions
> are necessary for a popup menu, or if I should be trying to make the menu a
> child to the TreeView, or the main window? At any rate, I'm seeing nothing,
> so don't quite know what to try next. My google searches all seem to be
> dealing with the older menu approach...
> Any help is appreciated, and thanks in advance!
> ------------------------------------------------------------------------
> No virus found in this incoming message.
> Checked by AVG - www.avg.com 
> Version: 8.5.339 / Virus Database: 270.12.36/2126 - Release Date: 05/21/09 06:22:00
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/gtk-sharp-list/attachments/20090522/bda90c67/attachment.html 

More information about the Gtk-sharp-list mailing list