【问题标题】:Convert Gtk.TreeView into a text format将 Gtk.TreeView 转换为文本格式
【发布时间】:2016-06-21 06:02:11
【问题描述】:

我正在尝试将 Gtk.TreeView 导出为文本格式。这就像应用程序上的导出到文本功能,它使用 ListStore 模型在 TreeView 中呈现数据。

有人可以提供有关如何有效解析 Gtk.TreeView 并以简单文本格式表示它的示例代码的帮助。

【问题讨论】:

标签: treeview gtk vala


【解决方案1】:

首先考虑this code from valadoc

public static int main (string[] args) {
    // Create a ListStore:
    Gtk.ListStore list_store = new Gtk.ListStore (2, typeof (string), typeof (int));
    Gtk.TreeIter iter;

    // Insert data: (0: State, 1: Cities)
    list_store.append (out iter);
    list_store.set (iter, 0, "Burgenland", 1, 13);
    list_store.append (out iter);
    list_store.set (iter, 0, "Carinthia", 1, 17);
    list_store.append (out iter);
    list_store.set (iter, 0, "Lower Austria", 1, 75);
    list_store.append (out iter);
    list_store.set (iter, 0, "Upper Austria", 1, 32);
    list_store.append (out iter);
    list_store.set (iter, 0, "Salzburg", 1, 10);
    list_store.append (out iter);
    list_store.set (iter, 0, "Styria", 1, 34);
    list_store.append (out iter);
    list_store.set (iter, 0, "Tyrol", 1, 11);
    list_store.append (out iter);
    list_store.set (iter, 0, "Vorarlberg", 1, 5);
    list_store.append (out iter);
    list_store.set (iter, 0, "Vienna", 1, 1);

    // Output:
    //  ``Entry: Burgenland     13``
    //  ``Entry: Carinthia      17``
    //  ``Entry: Lower Austria  75``
    //  ``Entry: Upper Austria  32``
    //  ``Entry: Salzburg       10``
    //  ``Entry: Styria         34``
    //  ``Entry: Tyrol          11``
    //  ``Entry: Vorarlberg     5``
    //  ``Entry: Vienna         1``
    for (bool next = list_store.get_iter_first (out iter); next; next = list_store.iter_next (ref iter)) {
        Value val1, val2;
        list_store.get_value (iter, 0, out val1);
        list_store.get_value (iter, 1, out val2);
        stdout.printf ("Entry: %s\t%d\n", (string) val1, (int) val2);
    }
    return 0;
}

您还应该阅读top level documentation for the Gtk.TreeModel interface

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-08
    • 1970-01-01
    • 2013-11-11
    • 1970-01-01
    • 1970-01-01
    • 2017-10-10
    • 1970-01-01
    • 2021-12-08
    相关资源
    最近更新 更多