Solved

Visual Studio 2005 ListView Error

Posted on 2007-11-19
5
775 Views
Last Modified: 2013-11-26
Hi

I am trying to gather the values of a ListView control into variables on the selection_changed event but am getting an error. The code is as follows:

        Dim s1 As Object
        Dim s2 As Object
        Dim s3 As Object

        Dim SelInd As Object = Me.lsbAnchor.SelectedIndices(0)

        s1 = Me.lsbAnchor.Items(SelInd).SubItems(0).Text
        s2 = Me.lsbAnchor.Items(SelInd).SubItems(1).Text
        s3 = Me.lsbAnchor.Items(SelInd).SubItems(2).Text
0
Comment
Question by:murbro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 

Author Comment

by:murbro
ID: 20312932
The error that I am getting is on the line
"Dim SelInd As Object = Me.lsbAnchor.SelectedIndices(0)"
The error is as follows
InvalidArgument=Value of '0' is not valid for 'index'.
Parameter name: index

0
 
LVL 11

Expert Comment

by:DotNetThinker
ID: 20313152
Try assigning SelInd a value in the ListBox_Load event. I think what's happening is that you're trying to grab a value out of the listbox before it's being populated.
0
 

Accepted Solution

by:
murbro earned 0 total points
ID: 20313637
Hi

found the answer
@That's because the event fires twice. Once for the item being selected, and once for the item that is no longer selected. Just check the SelectedItems.Count for > 0 before perforrming any operations on the first item in the collection.
0
 

Author Comment

by:murbro
ID: 20463037
thanks
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

738 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