Many thanks for your help ...
At first it worked great
When using it like this ..
Private Sub Listview_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Listview.SelectedIndexChanged
txtName.Text = Listview.SelectedItems.Item(0).SubItems(1).Text
End Sub
Strange problems occure ...
The first time I select something, it works fine.. the data from the
listview go's into the textfield.
When i select something else, I get a ArgumentOutOfRangeException ...
Any idea's?
john
If there are no selected items you will get this error. Check the SelectedItems.Count Property.
See inline.
> Many thanks for your help ...
>
[quoted text clipped - 4 lines]
> Private Sub Listview_SelectedIndexChanged(ByVal sender As System.Object,
> ByVal e As System.EventArgs) Handles Listview.SelectedIndexChanged
If Listview.SelectedItems.Coun > 0 Then
> txtName.Text = Listview.SelectedItems.Item(0).SubItems(1).Text
Endif
> End Sub
>
[quoted text clipped - 7 lines]
>
> john
--
Al Reid
John Devlon - 28 Aug 2006 15:33 GMT
Hi,
I've tested the application using your code and I found the problem ...
When selecting something else in a Listview, the methode that handles the
SelectedIndexChanged
is triggerd twice....
First, it sets the selectedItems to 0, then to 1, represting the new
selected value ...
Strang, but the problem is solved ..
Many, Many thanx....
> If there are no selected items you will get this error. Check the
> SelectedItems.Count Property.
Claes Bergefall - 28 Aug 2006 16:12 GMT
> Hi,
>
[quoted text clipped - 8 lines]
>
> Strang, but the problem is solved ..
Not that strange. This is by design. When you select an item in a ListView
it first deselects the previously selected item and this triggers the first
SelectedIndexChanged (were count = 0). Then it selects the item you clicked
on and this triggers the second SelectedIndexChanged (were count = 1). Hence
the check on count is necessary.
/claes