07.06.2024 16:58 Gtk3
Приклад №3 використання віджету TreeView.
Різні варіанти колонок: іконка, випадаючий список, прапорець і комірка для редагування тексту.

dotnet new consoledotnet add package GtkSharpdotnet runusing Gtk;
class Program
{
public static void Main()
{
Application.Init();
new FirstWindow();
Application.Run();
}
public static void Quit()
{
Application.Quit();
}
}using Gtk;
class FirstWindow : Window
{
public FirstWindow() : base("Test")
{
SetDefaultSize(600, 350);
SetPosition(WindowPosition.Center);
DeleteEvent += delegate { Program.Quit(); };
VBox vBox = new VBox();
Add(vBox);
HBox hBox = new HBox();
vBox.PackStart(hBox, false, false, 5);
ListStore store = new ListStore
(
typeof(Gdk.Pixbuf),
typeof(string),
typeof(bool),
typeof(string)
);
TreeView treeView = new TreeView(store);
treeView.AppendColumn(new TreeViewColumn("Img", new CellRendererPixbuf(), "pixbuf", 0));
//Variant
{
ListStore storeVariant = new ListStore(typeof(string), typeof(string));
storeVariant.AppendValues("1", "Type №1");
storeVariant.AppendValues("2", "Type №2");
storeVariant.AppendValues("3", "Type №3");
CellRendererCombo variant = new CellRendererCombo() { Editable = true, Model = storeVariant, TextColumn = 1 };
treeView.AppendColumn(new TreeViewColumn("Variant", variant, "text", 1) { MinWidth = 100, Resizable = true });
}
treeView.AppendColumn(new TreeViewColumn("Active", new CellRendererToggle(), "active", 2));
treeView.AppendColumn(new TreeViewColumn("Editable", new CellRendererText() { Editable = true }, "text", 3) { MinWidth = 100, Resizable = true });
//Пустишка для заповнення вільного простору
treeView.AppendColumn(new TreeViewColumn());
var img = new Gdk.Pixbuf("form.ico", 16, 16);
store.AppendValues(img, "1", false, "text");
store.AppendValues(img, "2", true, "text");
store.AppendValues(img, "3", false, "text");
hBox.PackStart(treeView, true, true, 5);
ShowAll();
}
}© accounting.org.ua - 2025