Reputation: 3185
I have a listview in VB.net that I'm filling from a table in my SQL database. The listview refreshes every period of time (using a timer) and I want every dynamically added item to be added on the TOP of the listview.
Here's my code:
Dim itm as Listviewitem
arr(0) = Date.Now.ToString
arr(1) = Table.item("no")
arr(2) = Table.item("datain")
arr(3) = Table.item("message")
itm = New ListViewItem(arr)
ListView1.Items.Add(itm)
Any idea how to do this?
Upvotes: 5
Views: 8116
Reputation: 34846
Use the Insert
method instead of Add
, like this:
ListView1.Items.Insert(0, itm)
Note: 0 is the index of the first item in the list, so this puts it at the beginning.
Upvotes: 5
Reputation: 3047
Instead of simply adding the item to the list, use the insert function :
ListView1.Items.Insert(0, itm)
Upvotes: 1