How to add item to the beginning of the list in ListBox?

kyrisu picture kyrisu · May 4, 2009 · Viewed 58.5k times · Source

Is there a way to add item to a WinForms ListBox, to the beginning of the list without rewriting entire list in a loop?

Other way to solve my problem would be to display ListBox in reverse order (last item on the top) but I don't know how to do it.

My ListBox control is used as a log viewer where the most recent entry should be on the top.

Answer

bruno conde picture bruno conde · May 4, 2009

Use the Insert method on the items of your ListBox.