Uso de gtk# treeview

Solo disponible en BuenasTareas
  • Páginas : 15 (3601 palabras )
  • Descarga(s) : 0
  • Publicado : 13 de enero de 2011
Leer documento completo
Vista previa del texto
GtkSharp TreeView Tutorial - Mono

Página 1 de 16

■ ■ ■ ■ ■ ■ ■ ■ Home Download Start News Contribute Community Support Store

Search Mono

GtkSharp TreeView Tutorial
Table of Contents

1 Introduction 2 Model, View, Controller 2.1 Model 2.2 View 2.3 Controller 3 Your first TreeView 3.1 Setting it up 3.2 Adding some data 4 Creating a Tree 5 Filtering Data 6 Controlling howthe model is used 7 Shortcuts - Writing Less Code 8 Editable Text Cells 9 Drawing icons in rows

The GTK TreeView widget is used to display data in one of the most basic and intuitive ways possible: a list. Each row in the list can be separated into multiple columns, and rows in the list can contain child rows to create an expandable-list, or tree. The TreeView can be extremelyintimidating at first, but it is extremely powerful - especially when compared to the ListBox and ListView controls from the Windows Forms toolkit.

Model, View, Controller
The TreeView uses the Model-View-Controller (MVC) design pattern. Components of the TreeView are separated into these three categories: The Model, which stores data to be displayed, the View, which controls how to display thedata, and the controller, which controls what data is displayed, how it is sorted, etc.


GtkSharp TreeView Tutorial - Mono

Página 2 de 16

The TreeView has two basic models: ListStore, which stores a flat set of data, and TreeStore, which stores data that can contain sub-items (used for creating a Tree). AllTreeView Models implement the Gtk.TreeModel interface.

The View is made up of three different parts as well - The column, the cell renderers, and the widget itself. The TreeView widget is responsible for laying out the columns and rows of data, as well as providing all the basic user-interaction functionality such as selecting items, etc. Each TreeViewColumn contains at least one CellRenderer.Cell renderers are what actually display the data items in the model are mapped to cell renderers. The following cell renderers are available: ■ ■ ■ ■ ■ CellRendererText - Used to display text CellRendererPixbuf - Used to display images CellRendererProgress - Used to display a progress bar CellRendererCombo - Used to display a drop-down box CellRendererToggle - Used to display a check boxCellRenderers are seporate from TreeViewColumns for added flexibility, allowing you to have an extremely fine-tuned treeview tailored to your application. For example you can pack an image and text into the same column, which often makes much more sense than creating a separate column for each.

Controllers modify how the data in the model is passed off to the View, and let you do thingssuch as sorting and filtering the data.

Your first TreeView
Setting it up
Here is a basic example of how to use the TreeView and all its related components. In our example, we will show a simple list of song titles and artist names:
#file: TreeViewExample.cs //mcs -pkg:gtk-sharp TreeViewExample.cs public class TreeViewExample { public static void Main () { Gtk.Application.Init (); newTreeViewExample (); Gtk.Application.Run (); } public TreeViewExample () { // Create a Window Gtk.Window window = new Gtk.Window ("TreeView Example"); window.SetSizeRequest (500,200); // Create our TreeView Gtk.TreeView tree = new Gtk.TreeView ();


GtkSharp TreeView Tutorial - Mono

Página 3 de 16

// Add our tree to thewindow window.Add (tree); // Create a column for the artist name Gtk.TreeViewColumn artistColumn = new Gtk.TreeViewColumn (); artistColumn.Title = "Artist"; // Create a column for the song title Gtk.TreeViewColumn songColumn = new Gtk.TreeViewColumn (); songColumn.Title = "Song Title"; // Add the columns to the TreeView tree.AppendColumn (artistColumn); tree.AppendColumn (songColumn); // Create a...
tracking img