[Gtk-sharp-list] Add a menu to a treeview

Fredrik Nilsson jymdman@home.se
Thu, 29 Jul 2004 01:15:17 +0200


On ons, 2004-07-28 at 22:48 +0200, Raúl Moratalla wrote:
> Hi! It's Raúl again with another question about gtk# ;)
> I want to display a menu when the user clicks (with right button) on a
> cell of a treeview. I searched in the code of monodevelop but I couldn't
> find the part of the code that do it.
> I'm sorry if I make too many questions but there is no much
> documentation about gtk# and there are a few applications that are
> developed using mono/gtk#.
> 
> Cheers,
> 
> Raúl
> 
> 

Hi again ;)

Let's see if I can help you once again.... :)

Define this signal to the treeview:

  treeview1.ButtonPressEvent += OnTreeview1ButtonPressEvent

The Signalhandler looks like this:

  [ConnectBefore]
  public void OnTreeview1ButtonPressEvent (object o,
ButtonPressEventArgs args)
  {
    Gdk.EventButton eb = args.Event;

    if (eb.Button == 3) { // Right click
      // pop up menu here...

      Console.WriteLine ("Right click");
    }
  }


/Fredrik