Solved

Visual Studio 2005 ListView Error

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
WPF - Tooltips for ComboBox items 5 68
execute SQL Stored Procedure 1000 times from vb.net 3 33
SQL Help 27 41
Convert datetime to time string 10 19
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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

785 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