[Gtk-sharp-list] TreeView Help Needed
Томислав Марковски
tome@users.ossm.org.mk
Fri, 06 Aug 2004 23:28:26 +0200
--=-9AkzImvfNVRrElvrQo+u
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On =D0=BF=D0=B5=D1=82, 2004-08-06 at 22:55, Mario Carrion wrote:
> There's an example at monodoc, it was useful for me.
Kaya sent me an example file which was very helpful. Thanks Kaya. I'm
attaching that file in case anyone else needs it. So, I figured that
out, and I'm moving on to the more challenging stuff. I need to make a
tree structure, just like the monodoc class listing. I only need one
level of nesting the items, if you understand what I mean.
Ex.
+Group 1
|--Element in group 1
|--Another element
+Group 2
|--Element in group 2
and so on...
Any pointers on this one?
I've already made a big progress and would like to finish what I've
started.
Thanks again for your help.
Tomislav
--=-9AkzImvfNVRrElvrQo+u
Content-Disposition: attachment; filename=tvclick.cs
Content-Type: text/x-csharp; name=tvclick.cs; charset=us-ascii
Content-Transfer-Encoding: 7bit
// Mario Fuentes <mario@gnome.cl>
// Release under GNU/GPL license.
namespace Samples {
using System;
using Gdk;
using Gtk;
public class TVClick {
public static int Main (string [] args)
{
new TVClick ();
return 0;
}
Gtk.Window win;
Menu menu = null;
public TVClick ()
{
Application.Init ();
win = new Gtk.Window (Gtk.WindowType.Toplevel);
win.DeleteEvent += new DeleteEventHandler (DeleteEventCb);
win.Title = "Context Menus on Right Click sample";
ListStore model = new ListStore (typeof (Pixbuf), typeof (string));
Pixbuf icon = win.RenderIcon (Stock.Home, IconSize.LargeToolbar, null);
for (int i = 1; i < 10; i++)
{
model.AppendValues (icon, "<b>Elemento " + i + "</b>\nFila " + i);
}
TreeView tv = new TreeView (model);
// Add two Columns, a Image and a Label
tv.AppendColumn ("Icon", new CellRendererPixbuf (), "pixbuf", 0);
TreeViewColumn column = new TreeViewColumn ("Text",
new CellRendererText (), "markup", 1);
column.Clickable = true;
column.Clicked += new EventHandler (ColumnClickedCb);
tv.AppendColumn (column);
// Connect signals for mouse button press and popup menu
tv.ButtonPressEvent += new ButtonPressEventHandler (ButtonPressCb);
tv.PopupMenu += new PopupMenuHandler (PopupMenuCb);
win.Add (tv);
win.ShowAll ();
Application.Run ();
}
void PopupMenu (EventButton ev)
{
Console.WriteLine ("Popup Menu!");
if (menu == null)
{
menu = new Menu ();
AccelGroup group = new AccelGroup ();
ImageMenuItem item;
item = new ImageMenuItem (Stock.Add, group);
menu.Append (item);
item = new ImageMenuItem (Stock.Remove, group);
menu.Append (item);
}
menu.ShowAll ();
menu.Popup (null, null, null, IntPtr.Zero,
(ev != null) ? ev.Button : 0, (ev != null) ? ev.Time : 0);
}
[GLib.ConnectBefore]
void ButtonPressCb (object o, ButtonPressEventArgs args)
{
Console.WriteLine ("Pressed button {0}", args.Event.Button);
switch (args.Event.Button)
{
case 3:
PopupMenu (args.Event);
break;
}
}
void PopupMenuCb (object o, PopupMenuArgs args)
{
Console.WriteLine ("Popup Menu Called!");
PopupMenu (null);
}
void DeleteEventCb (object o, DeleteEventArgs args)
{
Application.Quit ();
args.RetVal = true;
}
void ColumnClickedCb (object o, EventArgs args)
{
Console.WriteLine ("Column Clicked!");
}
}
}
--=-9AkzImvfNVRrElvrQo+u--