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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ListView - Get Item Key

Status
Not open for further replies.

ProjectExplorer

Programmer
Mar 22, 2002
95
GB
I have created a ListView in VB.NET and added an item using:

lstView.Items.Add("Item/1", "An Item", 0)

Thus the item key is "Item/1".

How do I retrieve the item key. What event do I use etc.

Any help appreciated.

Thanks
 
What do you mean by retrieve the item key? I'm not sure what you are trying to do.
 
When you add each item you can give it a key (or name)as string, the item text as string and the image key.

The item key (or name) is a unique indentifier for the item.

In VBA you can use the Item-Click event which passes the Item as an object where you can get its item key. I can't find the same event or object in vb.net.
 
The argument to Add() is called Key, but the property to retrieve it is Item.Name. Nice.
 
Thanks for the response migr8now.

No doubt there is a logical reason for it hiding away in someone's head at Microsoft!

For those who also want to discover the "Secret of the Key" - you can retreive it with:

Private Sub lstContacts_ItemActivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstContacts.ItemActivate
Dim SelItems As ListView.SelectedListViewItemCollection = Me.lstContacts.SelectedItems
Dim Item As ListViewItem
For Each Item In SelItems
MsgBox(Item.Name)
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top