3 Replies - 474 Views - Last Post: 29 January 2013 - 11:19 AM Rate Topic: -----

#1 Bluezap  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 328
  • Joined: 19-January 12

ListView Index Issue

Posted 29 January 2013 - 12:13 AM

I need to get the name of the item that is select on a listview control onto my clipboard.
But every time the code executes this error appears.
"InvalidArgument=Value of '1' is not valid for 'index'.
Parameter name: index"

This is the Code -
  Dim x As Integer
        x = ListView1.FocusedItem.Index
        My.Computer.Clipboard.SetText("Name of Item is" + ListView1.SelectedItems(x).Text)



Is This A Good Question/Topic? 0
  • +

Replies To: ListView Index Issue

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1623
  • View blog
  • Posts: 5,199
  • Joined: 25-September 09

Re: ListView Index Issue

Posted 29 January 2013 - 05:32 AM

Have you tried just using
My.Computer.Clipboard.SetText("Name of Item is " & ListView1.FocusedItem.Text

Was This Post Helpful? 0
  • +
  • -

#3 Bluezap  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 328
  • Joined: 19-January 12

Re: ListView Index Issue

Posted 29 January 2013 - 10:57 AM

View PostCharlieMay, on 29 January 2013 - 05:32 AM, said:

Have you tried just using
My.Computer.Clipboard.SetText("Name of Item is " & ListView1.FocusedItem.Text

Thats working for me. But what seems to be wrong in the code i have mentioned above?
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3818
  • View blog
  • Posts: 13,534
  • Joined: 12-December 12

Re: ListView Index Issue

Posted 29 January 2013 - 11:19 AM

The FocusedItem Index does not correspond to the SelectedItems index.

SelectedItems is a collection of the currently selected items indexed from 0. So the first selected item would be Item(0):

MessageBox.Show(ListView1.SelectedItems.Item(0).Text)

whereas FocusedItem refers to (indexes) all of the available items in the control.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1