[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Visual Studio 2005 ListView Error

Posted on 2007-11-19
5
Medium Priority
?
779 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:Murray Brown
[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:Murray Brown
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:
Murray Brown 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:Murray Brown
ID: 20463037
thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

649 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