我想有一个TreeView,在哪个过滤器和排序工作。但是,我可以进行过滤器工作或分类工作,但不能同时进行。
以下是我的代码片段,当我点击列标题
时,过滤器可以使用,但不进行排序portsTreeModelFilter = new Gtk.TreeModelFilter (myListStore);
portsTreeModelFilter.set_visible_func(filterTree);
ports_tcp_table_treeview.set_model(portsTreeModelFilter);
Gtk.TreeModelSort portsTreeModelSort = new TreeModelSort.with_model (portsTreeModelFilter);
portsTreeModelSort.set_sort_column_id(4,SortType.DESCENDING);
这是过滤功能
private bool filterTree (TreeModel model, TreeIter iter){
bool isFilterCriteriaMatch = true;
//If there is nothing to filter then make the data visible
if (headerSearchBar.get_text() == ""){
isFilterCriteriaMatch = true;
}else{
string searchValueString = "";
GLib.Value searchValue;
int noOfColumns = model.get_n_columns();
for (int count = 0; count < noOfColumns; count++){
model.get_value (iter, count, out searchValue);
searchValueString = searchValue.get_string();
if (searchValueString.index_of(headerSearchBar.get_text()) > -1){
isFilterCriteriaMatch = true;
break;
}else{
isFilterCriteriaMatch = false;
}
}
}
return isFilterCriteriaMatch;
}
这就是当用户键入headersearch栏时调用过滤器函数的方法:
headerSearchBar.search_changed.connect (() => {
portsTreeModelFilter.refilter ();
});
感谢关于排序的工作的任何指针,以便点击列标题。 提前致谢