如何将项添加到ListBox列表的开头?

kyr*_*isu 23 c# listbox winforms

有没有办法将项添加到WinForms ListBox,到列表的开头而不重写循环中的整个列表?

解决我的问题的其他方法是以相反的顺序显示ListBox(顶部的最后一项)但我不知道如何做到这一点.

我的ListBox控件用作日志查看器,其中最新的条目应位于顶部.

bru*_*nde 35

Insert在你的项目上使用该方法ListBox.


Raz*_*zie 26

如果我理解正确,你不能使用这个Insert(int index, object item)方法吗?例如:

myListBox.Items.Insert(0, "First");
Run Code Online (Sandbox Code Playgroud)

这会将"First"作为列表框的第一项插入.