I have a listview which is populated with values from a data base. What i am trying to do is select an item from the listview via a checkbox and then have that value displayed in a listbox. But everytime all that is displayed in the list box is:

(Collection)


The code i am using to populate the listbox is:

lstResults.Items.Add(ListView1.SelectedItems)


I wondered if anyone had any ideas?

Regards

Recommended Answers

All 6 Replies

so, your checkbox on listview is true...

yes, the checkbox is true and this is how the selection is made on the listview.

I have started to get the result i want, but its not perfect.

the new code im using is:

For Each Item As Object In ListView1.CheckedItems
            lstResults.Items.Add(Item.ToString)


        Next

Now what i get written to the listbox is:

ListViewItem: {12}


With 12 being the value of the first column in the listbox, but all i want to e returned is the 12, and not all the other bits.

I wondered if anyone knew where i was going wrong?

Just a little wrong :

For Each Item As Object In ListView1.CheckedItems
        lstResults.Items.Add(Item.Text)
Next

hi

fixed it with this -

For Each itemlist As ListViewItem In ListView1.CheckedItems
            lstResults.Items.Add(itemlist.Text)


        Next

had to change it from 'object' to 'ListViewItem'

i then had the text option

many thanks for your help

you're welcome...
don't forget to mark this thread solved
Happy coding :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.