Jacqueline
Jacqueline

Reputation: 491

Index of inserted ListView item

How can i get the index when adding my item to the ListView?

Im adding the item as follows

flatListView1.Items.Add(name).SubItems.AddRange(row1);

Upvotes: 2

Views: 969

Answers (2)

Prabhu Murthy
Prabhu Murthy

Reputation: 9261

var lviewItem=flatListView1.Items.Add(name)
var index=flatListView1.Items.IndexOf(lviewItem)

http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.listviewitemcollection.indexof.aspx

Upvotes: 2

Adil
Adil

Reputation: 148110

You may need this, as the item added at the end of listitem and will be last. So total items -1 will be index because index starting from zero.

flatListView1.Items.Add(name).SubItems.AddRange(row1);
int index = flatListView1.Items.Count -1;

Upvotes: 2

Related Questions