如何仅添加 10 个项目
我已经取消了经理。 我只需要在列表视图中查看 10 个条目。 脑子已经沸腾了怎么办呢。
此代码将所有记录添加到视图列表中,但我只需要最后 10 条。
lvUndoStack.Items.Clear();
var list = new List<object>();
foreach (var command in UndoRedoManager.UndoCommands)
{
list.Insert(0, command.ToString());
}
lvUndoStack.Items.AddRange(list.ToArray());
lvUndoStack.SelectedIndex = lvUndoStack.Items.Count - 1;
indexSeletedItemUndoStack = lvUndoStack.SelectedIndex;
list = new List<object>();
foreach (var command in UndoRedoManager.RedoCommands)
{
list.Insert(0, command.ToString());
}
lvUndoStack.Items.AddRange(list.ToArray());
重要的是 - 未使用 linq
更新:
示例:
undo1
undo2
undo3
undo4
undo5
undo6
undo7
redo1
redo2
redo3
redo4
redo5
我需要 obly 10。如果 start undo4 then您需要显示最后或最多 10 条中的所有内容
I have undoredomanager.
And I need to view in listview only 10 entries.
already seething brain how to do it.
This code is added to the viewlist all records, but I only need the last 10.
lvUndoStack.Items.Clear();
var list = new List<object>();
foreach (var command in UndoRedoManager.UndoCommands)
{
list.Insert(0, command.ToString());
}
lvUndoStack.Items.AddRange(list.ToArray());
lvUndoStack.SelectedIndex = lvUndoStack.Items.Count - 1;
indexSeletedItemUndoStack = lvUndoStack.SelectedIndex;
list = new List<object>();
foreach (var command in UndoRedoManager.RedoCommands)
{
list.Insert(0, command.ToString());
}
lvUndoStack.Items.AddRange(list.ToArray());
importantly - not used linq
Update:
example:
undo1
undo2
undo3
undo4
undo5
undo6
undo7
redo1
redo2
redo3
redo4
redo5
I need obly 10. if start undo4 then you need to show everything in the last or a maximum of 10
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解你的问题,你最多需要最后 10 个撤消和最后 10 个重做命令。获得撤消命令列表后,使用它获取最后 10 个命令:
并对重做命令执行相同的操作。在我看来,这不是最好的解决方案——实际上更像是一个拼凑,但它应该让你朝着正确的方向前进。
更好的解决方案是修改/增强 UndoRedoManager 类,以便 ListView 可以调用方法来获取最后 n 个撤消/重做命令的列表。类似于:
然后 ListView 可以简单地调用该方法:
以及类似的重做命令。它从 UI 层中删除了一堆代码,并为您提供了在以后轻松切换最大项目数的灵活性,并且通常(再次在我看来)似乎是更好的方法。
If I understand your question, you want (at most) the last 10 undo and the last 10 redo commands. After you get the List of undo commands, use this to get up to the last 10:
And do the same for the redo commands. That's not the best solution, IMO - really more of a kludge, but it should get you going in the right direction.
An even better solution would be to modify/enchance the UndoRedoManager class so that the ListView could call a method to get a list of the last n undo/redo commands. Something like:
Then the ListView could simply call that method:
And something similar for the redo commands. It removes a bunch of code from your UI layer, and gives you the flexibility to easily switch the max number of items at a later date and just generally (again IMO) seems to be a better way to go.