Repost: Deleting last listview item 
Author Message
 Repost: Deleting last listview item

Try selecting the first item before deleting the last item. You haven't
mentioned what is displayIndex.
You might have some code in selectedIndexChanged event of the lsvTest. Are
you setting displayIndex =1 anywhere?

Private Sub DeleteMovie()
    Dim li As ListViewItem

    li = lsvTest.Items(lsvTest.SelectedItems(0).Index)
    lsvTest.Items(0).Selected = True  'This is just for testing. It won't
work for the very first item.
    lsvTest.Items.Remove(li)
End Sub


Quote:
> I am having a problem when deleting the very last item in
> a listview.

> I populate the listview that resides on a TabControl at
> runtime for example with 2 items. The if the user deletes
> the very last item in the list the program crashes. The
> error occurs in the procedure where I call
> FormMain.ShowDialog()

> The error message that I get is
> 5
> Specified argument was out of the range of valid values.
> Parameter name: '1' is not a valid value
> for 'displayIndex'.

> My Code:
> Private Sub DeleteMovie()
>     Dim li As ListViewItem

>     li = lsvTest.Items(lsvTest.SelectedItems(0).Index)
>     lsvTest.Items.Remove(li)
> End Sub

> It crashes when it exists the procedure that
> does the deleting.

> Has anyone encountered this problem?
> Is there a solution?
> Jeff



Mon, 16 May 2005 14:51:37 GMT  
 Repost: Deleting last listview item
Then what would I do when deleting the last item in the
list?

I mena when there is only one left.

Jeff

Quote:
>-----Original Message-----
>Try selecting the first item before deleting the last
item. You haven't
>mentioned what is displayIndex.
>You might have some code in selectedIndexChanged event
of the lsvTest. Are
>you setting displayIndex =1 anywhere?

>Private Sub DeleteMovie()
>    Dim li As ListViewItem

>    li = lsvTest.Items(lsvTest.SelectedItems(0).Index)
>    lsvTest.Items(0).Selected = True  'This is just for
testing. It won't
>work for the very first item.
>    lsvTest.Items.Remove(li)
>End Sub



>> I am having a problem when deleting the very last item
in
>> a listview.

>> I populate the listview that resides on a TabControl at
>> runtime for example with 2 items. The if the user
deletes
>> the very last item in the list the program crashes. The
>> error occurs in the procedure where I call
>> FormMain.ShowDialog()

>> The error message that I get is
>> 5
>> Specified argument was out of the range of valid
values.
>> Parameter name: '1' is not a valid value
>> for 'displayIndex'.

>> My Code:
>> Private Sub DeleteMovie()
>>     Dim li As ListViewItem

>>     li = lsvTest.Items(lsvTest.SelectedItems(0).Index)
>>     lsvTest.Items.Remove(li)
>> End Sub

>> It crashes when it exists the procedure that
>> does the deleting.

>> Has anyone encountered this problem?
>> Is there a solution?
>> Jeff

>.



Tue, 17 May 2005 07:39:53 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Delete last Listview Item

2. Listview box last item shown?

3. Listview : make last added item visible everytime ?

4. Problem displaying the last item in a ListView

5. How to iterate through and delete mutiple selected items from a listview

6. Delete Listview Item

7. Deleting ListView items

8. ListView.EnsureVisible near deleted item

9. listview delete items?

10. Deleting ListView items

11. Delete multiple listview items?

12. Quick Redraw a ListView After deleting Item(s)

 

 
Powered by phpBB® Forum Software