VB.NET Listview - Insert NOT Add
Full screen
VB.NET Topic list
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)
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.
Instead of simply adding the item to the list, use the insert function :
ListView1.Items.Insert(0, itm)
NOTE:-
For subitems the code is the same as ADD, only the LEAD item needs
the INSERT code.
https://stackoverflow.com/questions/19030741/vb-how-to-dynamically-add-items-on-top-of-listview
Copyright © 2015-19 Allied Factors Limited. All Rights Reserved.