如何更新 ArrayList 以匹配用户订购的 TreeView

How to update ArrayList to match user-ordered TreeView

我有一个 Gtk TreeView 显示 ArrayList 中的项目列表。 TreeView 设置为可重新排序,因此用户可以拖放列表中的项目以重新排序。

我的问题是,重新排序后如何更新原始 ArrayList 以匹配新的 TreeView 排序?

我想出了一个解决方案——下面的代码只是打印出列表中的所有项目;希望您可以了解如何通过这样做找到项目的正确索引,从而在关联的 ArrayList 中对它们重新排序。

        TreeIter iter;
        yourNodeView.Model.GetIterFirst (out iter);
        for (int i = 0; i < yourNodeView.Model.IterNChildren(); i++)
        {
            string result = ((TypeOfListItem)sequencerNodeView.Model.GetValue (iter, 0)).ToString();
            //Here you would add the TypeOfListItem instance to a new ArrayList, and then after the loop swap out the old ArrayList for the new one. 
            Console.WriteLine("print the item "+result);
            yourNodeView.Model.IterNext(ref iter);
        }

TypeOfListItem 当然可以是任何时间。我写了一个名为 MyListItem 的 Class,它具有标题和描述等参数,因此我可以通过以下方式访问它们:

string result = ((MyListItem)sequencerNodeView.Model.GetValue (iter, 0)).title;