MonoDevelop/GtkSharp - 如何将项目添加到列表的开始在TreeView?
问题描述:
是否可以将项目添加到列表/树顶部的GtkSharp TreeView?
这是可能在Windows窗体例如,通过这种方式:listBox.Items.Insert(0, "anyItem");
MonoDevelop/GtkSharp - 如何将项目添加到列表的开始在TreeView?
但是我注意到能够找到GtkSharp类似的解决方案。
答
创建一个ListStore或TreeStore对象并将其分配给TreeView的Model属性。然后,您可以使用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");
奇迹。它的工作原理非常感谢,但问题在于,垂直滚动条与第一项一起移动并且上面的新条目不能看到。你知道吗,请问如何解决这个问题?我很抱歉我的英语。 – skybedy
对此的其他信息 - 在WindowsForm中,这可以通过使用'listBox.SelectedIndex = 0'来实现,然后每个新项目都被选中并且可见。 Mono也有类似的可能吗? – skybedy
TreeView有一个ScrollToCell方法可以用来确保特定的行可见。 –