MonoDevelop / GtkSharp - 如何将项目添加到 TreeView 列表的开头?
MonoDevelop / GtkSharp - How to add item to the beginning of the list in TreeView?
是否可以将项目添加到 list/tree 顶部的 GtkSharp TreeView?
这在 Windows 形式中是可能的,例如通过这种方式:
listBox.Items.Insert(0, "anyItem");
不过我注意到能够在 GtkSharp 中找到类似的解决方案。
创建 ListStore 或 TreeStore 对象并将其分配给 TreeView 的模型 属性。然后您可以使用 ListStore 或 TreeStore 对象插入或添加项目。
下面是一个使用 ListStore 的简单示例。
var listView = new TreeView ();
listView.HeadersVisible = false;
listStore = new ListStore (typeof(string));
listView.Model = listStore;
var cellView = new CellRendererText ();
var column = new TreeViewColumn ("Title", cellView);
column.AddAttribute (cellView, "text", 0);
listView.AppendColumn (column);
然后您可以使用以下方式插入项目:
int position = 0;
listStore.InsertWithValues (position, "MyItem");
是否可以将项目添加到 list/tree 顶部的 GtkSharp TreeView?
这在 Windows 形式中是可能的,例如通过这种方式:
listBox.Items.Insert(0, "anyItem");
不过我注意到能够在 GtkSharp 中找到类似的解决方案。
创建 ListStore 或 TreeStore 对象并将其分配给 TreeView 的模型 属性。然后您可以使用 ListStore 或 TreeStore 对象插入或添加项目。
下面是一个使用 ListStore 的简单示例。
var listView = new TreeView ();
listView.HeadersVisible = false;
listStore = new ListStore (typeof(string));
listView.Model = listStore;
var cellView = new CellRendererText ();
var column = new TreeViewColumn ("Title", cellView);
column.AddAttribute (cellView, "text", 0);
listView.AppendColumn (column);
然后您可以使用以下方式插入项目:
int position = 0;
listStore.InsertWithValues (position, "MyItem");