c#-如何从GTK#中的TreeView中删除多行
作者:互联网
最近在单声道GTK#中从TreeView中删除多行使我有点绊倒了,答案不是google的快速搜索,所以我在这里发布了这个问题.与TreeView(TreeModelSort)一起使用排序时,删除多行已成问题.
解决方法:
以下函数可以删除未实现精美的TreeModelSort或TreeModelFilter的纯TreeView上的多个选定行:
private void RemoveSelectedRows(TreeView treeView, ListStore listStore)
{
TreeIter iter;
TreePath[] treePath = treeView.Selection.GetSelectedRows();
for (int i = treePath.Length; i > 0; i--)
{
listStore.GetIter(out iter, treePath[(i - 1)]);
string value = (string)listStore.GetValue(iter, 0);
Console.WriteLine("Removing: " + value);
listStore.Remove(ref iter);
}
}
此下一个函数可以删除确实实现TreeModelSort的TreeView上的多个选定行(如果您的TreeView使用TreeModelFilter,则可以应用类似的逻辑):
private void RemoveSelectedRows(TreeView treeView, ListStore listStore, TreeModelSort treeModelSort)
{
TreeModel model;
TreeIter iter;
TreePath[] treePath = treeView.Selection.GetSelectedRows(out model);
for (int i = treePath.Length; i > 0; i--)
{
model.GetIter(out iter, treePath[(i - 1)]);
string value = (string)model.GetValue(iter, 0);
Console.WriteLine("Removing: " + value);
TreeIter childIter = treeModelSort.ConvertIterToChildIter(iter);
listStore.Remove(ref childIter);
}
}
如果有人有更好的方法或在我的解决方案中发现任何错误,请发布修复程序,谢谢!
标签:mono,gtk,gtk-2,c 来源: https://codeday.me/bug/20191031/1975346.html