Solved

Visual Studio 2005 ListView Error

Posted on 2007-11-19
5
776 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

726 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