ArgumentOutofRangeException was unhandled in visual studio 2008

Posted on 2010-09-21
Medium Priority
Last Modified: 2012-05-10
I'm getting this error when trying this code below
InvalidArgument=Value of '1' is not valid for 'index'. Parameter name: index

Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
               Me.txt_Owner.Text = ListView1.SelectedItems(0).Text
            Me.txt_Component.Text = ListView1.SelectedItems(1).Text

    End Sub

Please assist.
Question by:angel7170
  • 4
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33726598
you are trying to pass listview item to a textbox?
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33726638
try this

Dim str As string 'or integer

        For Each sItem As ListViewItem In lvList.SelectedItems
          str = sItem.Text 'this gives you the text of the first column 
          str = sItem.SubItems(2).Text 'this gives you the text of the third column 

Open in new window

LVL 18

Accepted Solution

John (Yiannis) Toutountzoglou earned 2000 total points
ID: 33726755
try my code in Listview Click or double click event

Author Comment

ID: 33726853
This code worked with slight modifications when in listview click

For Each sItem As ListViewItem In ListView1.SelectedItems

            Me.txt_Owner.Text = sItem.Text 'this gives you the text of the first column
            Me.txt_Component.Text = sItem.SubItems(1).Text 'this gives you the text of the third column

Thanks as always. your help is great in my project. I really appreciate
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33726892
very welcome...glad i helped you

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
If you are looking for an automated solution for backup single or multiple Office 365 user mailboxes to Outlook data file, then you can use Kernel Office 365 Backup & Restore tool. Go through the video to check out the steps to backup single or mult…

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question