我有一个经过过滤然后排序的 ListStore。它看起来像这样:
// Create a model for the cards
cardListStore = new ListStore (typeof (Card));
// Set up the tree view
cardFilter = new TreeModelFilter (cardListStore, null);
cardFilter.VisibleFunc = new TreeModelFilterVisibleFunc (FilterCards);
cardSort = new TreeModelSort (cardFilter);
cardTreeView.Model = cardSort;
当我右键单击它时,我希望获得一个特定于每一行的上下文菜单。我的点击处理程序看起来像这样:
[GLib.ConnectBeforeAttribute]
void HandleCardTreeViewButtonPressEvent (object o, ButtonPressEventArgs args)
{
if (args.Event.Button != 3)
return;
TreePath path;
// If right click on empty space
if (!cardTreeView.GetPathAtPos (Convert.ToInt32 (args.Event.X),
Convert.ToInt32 (args.Event.Y),
out path)) {
MakeCardEmptySpaceContextMenu ().Popup ();
return;
}
TreeIter iter;
if (!cardListStore.GetIter (out iter, path))
return;
Card card = (Card) cardListStore.GetValue (iter, 0);
MakeCardContextMenu (card, iter).Popup ();
}
这在 ListStore 未过滤或排序时有效。但是当它出现时,它给出了错误的行。
例如,假设行在排序之前看起来像这样:
甲乙丙
_
_
排序后,它们看起来像这样:
B
A
C
右键单击第二行(“A”)会给你“B”,因为那是模型排序之前 B 所在的位置。过滤也会发生同样的事情。说模型,过滤后的样子是这样的:
交流电_
右键单击第二行(“C”)仍然会给你“B”。
知道如何解决这个问题吗?