Aca del dejo como crear un TreeView en GKT#, bajo monodevelop 5.10 Linux aunque tambien funciona para Xamarin Studio sin problemas
Librerias a Usar
using System;
using Gtk;
using Gdk;
using Glade;
using Npgsql;
using System.Collections;
using System.Data;
using System.Collections.Generic;
Llamada del scrip
Explicacion del arreglo
{ "Cant.", "text","","","","","true"},
0 titulo
1 tipo de la columna
2 ancho de la columna
3 R Color
4 G Color
5 B Color
6 true visualiza columna false oculta columna
void crea_treeview()
{
object[] parametros = { treeview_concepto_remis,treeViewEngineconcepremis};
string[,] coltreeview = {
{ "Cant.", "text","","","","","true"},
{ "Ref.", "text","","","","","true" },
{ "Descripcion", "text","400","","","","true" },
{ "Pre. Unitario", "text","","","","","true" },
{ "Total", "text","","","","","true" },
{ "Lote", "text","100","","","","true" },
{ "Caducidad", "text","80","","","","true" },
{ "Cod. Barra", "text","","","","","true" },
{ "Ref.", "text","","","","","true" },
{ "ID Producto", "text","","","","","true" },
{ "Nro.remision", "text","","","","","false" }
};
crea_colums_treeview (parametros, coltreeview,"treeview_concepto_remis");
}
Como se crea automaticamente las columnas del TreeView
void crea_colums_treeview(object[] args,string [,] args_colums,string nombre_treeview_)
{
//var columns_renderertext = new List
//var columns_renderertoggle = new List
Gtk.CellRendererText text;
Gtk.CellRendererToggle toggle;
Gtk.TreeView treeviewobject = null;
Gtk.ListStore treeViewEngine = null;
ArrayList columns = new ArrayList ();
treeviewobject = (object) args[0] as Gtk.TreeView;
treeViewEngine = (object) args[1] as Gtk.ListStore;
var columns_treeview = new List
foreach (TreeViewColumn tvc in treeviewobject.Columns)
treeviewobject.RemoveColumn(tvc);
Type[] t = new Type[args_colums.GetUpperBound (0)+1];
for (int colum_field = 0; colum_field <= args_colums.GetUpperBound (0); colum_field++) {
if ((string)args_colums [colum_field, 1] == "text") {
t [colum_field] = typeof(string);
}
if ((string)args_colums [colum_field, 1] == "toogle") {
t [colum_field] = typeof(bool);
}
}
treeViewEngine = new Gtk.ListStore(t);
//treeViewEngine = liststore_;
treeviewobject.Model = treeViewEngine;
treeviewobject.RulesHint = true;
//treeviewobject.Selection.Mode = SelectionMode.Multiple;
if (args_colums.GetUpperBound (0) >= 0) {
for (int colum_field = 0; colum_field <= args_colums.GetUpperBound (0); colum_field++) {
if ((string)args_colums [colum_field, 0] != "") {
if ((string)args_colums [colum_field, 1] == "text") {
// column for holiday names
text = new CellRendererText ();
text.Xalign = 0.0f;
columns.Add (text);
columns_treeview.Add (new TreeViewColumn ((string)args_colums [colum_field, 0], text, "text", colum_field));
//columns_renderertext.Add (new CellRendererText ());
//columns_renderertext [colum_field+1].Xalign = 0.0f;
//columns.Add (columns_renderertext [colum_field+1]);
//columns_treeview.Add (new TreeViewColumn ((string)args_colums [colum_field, 0], columns_renderertext [colum_field], "text", colum_field));
// ancho de la columna
if ((string) args_colums [colum_field, 2] != "") {
text.Width = int.Parse((string) args_colums [colum_field, 2]);
}
// color de la columna
if ((string) args_colums [colum_field, 3] != "") {
text.CellBackgroundGdk = new Gdk.Color (byte.Parse((string) args_colums [colum_field, 3]), byte.Parse((string) args_colums [colum_field, 4]), byte.Parse((string) args_colums [colum_field, 5]));
}
if (nombre_treeview_ == "treeview_concepto_remis"){
if(colum_field == 0) {
text.Editable = true;
text.Edited += NumberCellEdited_cantremis;
}
if(colum_field == 2) {
text.Editable = true;
text.Edited += NumberCellEdited_concepto;
}
if(colum_field == 3) {
text.Editable = true;
text.Edited += NumberCellEdited_precioremis;
}
if(colum_field == 5) {
text.Editable = true;
text.Edited += NumberCellEdited_lote;
}
if(colum_field == 6) {
text.Editable = true;
text.Edited += NumberCellEdited_caducidad;
}
}
}
if ((string)args_colums [colum_field, 1] == "toogle") {
// column for holiday names
toggle = new CellRendererToggle ();
toggle.Xalign = 0.0f;
columns.Add (toggle);
columns_treeview.Add (new TreeViewColumn ((string)args_colums [colum_field, 0], toggle, "active", colum_field));
//columns_renderertoggle.Add(new CellRendererToggle());
//columns_renderertoggle[colum_field].Xalign = 0.0f;
//columns.Add (columns_renderertoggle[colum_field]);
//columns_treeview.Add (new TreeViewColumn ((string)args_colums [colum_field, 0], columns_renderertoggle[colum_field], "active", colum_field));
//toggle.Toggled += new ToggledHandler (selecciona_fila);
// ancho de la columna
if ((string) args_colums [colum_field, 2] != "") {
toggle.Width = int.Parse((string) args_colums [colum_field, 2]);
}
// color de la columna
if ((string) args_colums [colum_field, 3] != "") {
toggle.CellBackgroundGdk = new Gdk.Color (byte.Parse((string) args_colums [colum_field, 3]), byte.Parse((string) args_colums [colum_field, 4]), byte.Parse((string) args_colums [colum_field, 5]));
}
}
columns_treeview [colum_field].Resizable = true;
treeviewobject.InsertColumn (columns_treeview [colum_field], colum_field);
columns_treeview [colum_field].Visible = Convert.ToBoolean((string)args_colums [colum_field, 6]);
}
}
if (nombre_treeview_ == "treeview_concepto_remis"){
//treeview_concepto_remis.RowActivated += on_button_ligar_erp_clicked;
treeview_concepto_remis = treeviewobject;
treeViewEngineconcepremis = treeViewEngine;
}
if (nombre_treeview_ == "treeview_lista_remisiones") {
treeview_lista_remisiones.RowActivated += on_button_abrirremis_clicked;
treeview_lista_remisiones = treeviewobject;
treeViewEngineListaRemis = treeViewEngine;
}
}
}
No hay comentarios:
Publicar un comentario