|
-
Jan 15th, 2009, 08:49 PM
#1
Thread Starter
Hyperactive Member
arguement out of range
why doesnt this work?
Code:
Sub LstConnectionDataSelectedIndexChanged(sender As Object, e As EventArgs)
me.txtserver.text = Me.lstConnectionData.SelectedItems(0).text
End Sub
i am getting an arguement out of range. using sharpdevelop and .net 3.5... I have multiselect set to false.
-
Jan 15th, 2009, 08:57 PM
#2
Re: arguement out of range
If the index 0 is out of range then there is no item at index 0, i.e. there are no items in the collection.
Let me guess: lstConnectionData is a ListView, right? When you change the selection in a ListView the SelectedIndexChanged event is raised twice: once as the old item is deselected and once as the new item is selected. The first time there is no item selected so you have to ignore it, which would require an If statement that tests that there is at least one item selected.
-
Jan 15th, 2009, 09:07 PM
#3
Thread Starter
Hyperactive Member
Re: arguement out of range
there are items in the collection and it would be the second part of your post as it does work the first time. Just not if I select another item. I want to populate a textbox each time a new listviewitem is selected. How can I do that then?
-
Jan 15th, 2009, 09:12 PM
#4
Re: arguement out of range
You seem to have simply ignored what I said and stuck to what you assume is the case. First up, there can't possibly be items in the collection if index 0 is out of range. We're talking about the SelectedItems collection here, not the Items collection. Secondly, I've already told you what to do. If you just do it it will work. Add an If statement that tests the number of items in the collection, i.e. its Count property, and only try to access the first item IF there are items present.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|