How to use GtkTreeView correctly

I am using TreeView with a ListStore model. When the user clicks on the row, I want to take some action, but not use the values ​​in the cells, but using the data I created, the row from ...

I currently have TreeView, TreeModel (ListStore) and my own data (which I ironically call a model).

So the questions are:

Is it right to have a model - an object representation of the data that I want to display and populate the ListStore with these data for display in the TreeView, or would it be better to implement my own version of TreeModel (wrapping my data model) to display the data?

And:

If someone double-clicks on a line, I can get the RowActivated event (using C # / Gtk #), which provides the path to the activated line. With this, I can get a TreeIter and use this to get the cell value. But what is the best practice for finding the data object from which the row was built first? \ (Somehow this question drew me to the first - thinking that getting a data object would be easier if I try to implement my own TreeModel ...)

+5
source share
1 answer

It is very difficult / difficult to implement TreeModel, so most people simply synchronize data from their "real" model with a TreeStore or ListStore.

- . , , .

cellrenderer TreeView (), . , , - . , cellrenderer , .

:

treeView.AppendColumn ("Title", renderer, "text", 0, "editable", 4);

0 text GTK 4 editable. GTK GTK. , , , params. , , , TreeViewColumn.AddAttribute TreeViewColumn.SetAttributes.

, . , TreeIter , , , , , .

, , :

treeColumn.SetCellDataFunc (renderer, delegate (TreeViewColumn col,
    CellRenderer cell, TreeModel model, TreeIter iter)
{
    var textCell = (CellRendererText) cell;
    textCell.Text = (string) model.GetValue (iter, 0);
    textCell.Editable = (bool) model.GetValue (iter, 4);
});

, , GTK, - , , .

+7

All Articles