Click here to Skip to main content
15,896,379 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a list view that is 5 columns and i have it so i can select multiple items. I can get all the items names from column one just fine but i need a msgbox to display that selected items subitem(1).

the below code im using gets me one item but if i select multiple i get errors.
this is the layout of what data shows for the list view

1 | name | lastname | date | install

now i can get the column with the numbers in it just fine but i need the name to show up in a msgbox for the multiple selected items. Thanks for the help.

VB
Dim Zheap_num = CAE_Listview.SelectedItems(0).SubItems(1).Text ' heap name

For Each sITEM In Zheap_num
    MsgBox(sITEM)
Next
Posted

1 solution

For multiple selection in ListView you have to set the MultiSelect property of ListView to true. Then use the SelectedItems property, which returns SelectedListViewItemCollection
Then iterate this collection to get the Text property of each sub item
VB
'In the form load event set
CAE_ListView.MultiSelect=True

'Iterate the selected items
Dim Msg as string=""
For Each sITEM as ListViewItem In CAE_Listview.SelectedItems
    Msg &= sITEM.Subitems(1).Text & VbCrLf
Next
MessageBox.Show(Msg)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900