Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I have a new item appear on top in a ListView? 1

Status
Not open for further replies.

skhoury

IS-IT--Management
Nov 28, 2003
386
US
Hello all,


does anyone know how to make a new item being added to a ListView show up at the top of the list, rather than the bottom?

Any leads are much appreciate.

Thanks!

Sam
 
lstMyList.Items.Insert(0, myString); should do it

Age is a consequence of experience
 
in reality - you need to create an IComparer class and set listview1.ListViewItemSorter = yourIcomparerclass;

Look into IComparer and ListViewItemSorter. That should get you somewhere.

As an added note: when you set lstview1.ListViewItemSorter, make sure you set it to null first, and then to your comparer.
 
+1 for implementing IComparer.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
JunkMonkey - awesome, I'm goign to try it out.

Thanks for the tips guys, Sam.
 
IComparer might be overkill if all he's trying to do is insert at the top. But that's just me.
 
Neil - is there a more efficent/quicker way to do it other than using an IComparer?
 
as litton1 pointed out, just insert with an index, such as this:

lstMyList.Items.Insert(0, myString);

That basically adds the new item as index zero, and bumps the rest down a notch.

You only need IComparer if you want to sort the whole list by a particular column
 
Doh - you're right.

And I just tried it and it works like a charm.

Fortunatly, I dont need any sorting (at the moment).

Thanks,

Sam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top