Hack Forums
[.NET] add listview items on top of the list - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] add listview items on top of the list (/showthread.php?tid=5646022)



add listview items on top of the list - Johan Cruyff - Jun 13, 2017

When I add a new item to my listview I don't wanna add it down the list but I want it on top of the list as the first item.
How can I reverse this?

My current code is:
Code
Dim item1 As New ListViewItem("item1")
        ' Place a check mark next to the item.
        item1.Checked = True
        item1.SubItems.Add(ToolStripStatusLabel4.Text)
        item1.SubItems.Add(ToolStripStatusLabel7.Text)
        item1.SubItems.Add(NumericUpDown1.Text)
        ListView1.Items.AddRange(New ListViewItem() {item1})



* - +Haze - Jun 13, 2017

Do you even bother to Google? I searched your thread title and appended vb.net and I got the answer on the first click.


* - Johan Cruyff - Jun 13, 2017

(Jun 13, 2017 12:42 PM)+Haze Wrote:  Do you even bother to Google? I searched your thread title and appended vb.net and I got the answer on the first click.

I always google before asking but I just can't find it, I landed on SQL, .net and other stuff.
I'd like to know what you've found, you probably use different terms.


* - Ninja - Jun 13, 2017

(Jun 13, 2017 01:07 PM)Johan Cruyff Wrote:  I always google before asking but I just can't find it, I landed on SQL, .net and other stuff.
I'd like to know what you've found, you probably use different terms.

I Googled the same thing as Haze and as well got the result on the top result.

Indeed, the title says something about SQL, but if you were to actually check out the answers you would see the first answer gives you the answer you are looking for. You should check out most results that are even in the slightest relevant to get your answers.


* - idb. - Jun 13, 2017

Code
Dim item As New ListViewItem()
item.Checked = True
item.Text = "I am not"
item.SubItems.Add("even making an attempt")
item.SubItems.Add("to learn how to do this.")

Dim lv As New ListView
lv.Items.Insert(0, item)



* - Johan Cruyff - Jun 14, 2017

(Jun 13, 2017 02:06 PM)idb. Wrote:  
Code
Dim item As New ListViewItem()
item.Checked = True
item.Text = "I am not"
item.SubItems.Add("even making an attempt")
item.SubItems.Add("to learn how to do this.")

Dim lv As New ListView
lv.Items.Insert(0, item)


Thanks, this works perfectly :)