Solved

Visual Studio 2005 ListView Error

Posted on 2007-11-19
5
769 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now