Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Could someone please explain this for me

Status
Not open for further replies.

Savil

Programmer
Apr 28, 2003
333
0
0
EU
Hi
I have a listview control which is populated by an sql serer source which works fine. What I want is when the control is clicked it shows the value in a message box. The first time after the form is opened it works but if you click the control again I get the message

"Specified argument was out of the range of valid values."
I don't understand what this means. Here is the code for the listview control

Private Sub lstvwUsers_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstvwUsers.SelectedIndexChanged

Dim lvi As ListViewItem = Me.lstvwUsers.SelectedItems(0)
MsgBox(lvi.Text.Trim())
End Sub


Thanks
 
Interesting. I would guess that either the second click is not selecting an item, or that the event fires twice. Once for the deselection of the initial selection, and again for the selection of the second selection.

In either case, check the .Length property of the .SelectedItems collection to make sure there is an item selected before trying to access it.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
The event does fire twice - to unselect and then select the new item.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top