Problem deleting Last Row in ListView

  • Thread starter Thread starter A_PK
  • Start date Start date
A

A_PK

I am writing mobile application using Vb.net

when i click the last row of list view, and try to delete it....
will promtpy the following message "Additional information:
ArgumentOutOfRangeException"

what does that mean ?

I can delete any row without problem but except last row only....
 
Show us the code... If you are using the index for deleting you should be
adjusting by -1

Cheers
Daniel
 
A,

Test in your delete method if there are still enough items to delete, this
can occur when you have not done that and a delete button is pushed twice at
the end.

I hope this helps?

Cor
 
If you have 5 rows delete row number 4 as the rows are zero based. It means:
Rows: 0,1,2,3,4 (5 rows)
 
The following is the code that I delete my last row in List VIew

-----
With ListView1.FocusedItem

ListView1.Items.Remove(ListView1.Items(.Index))

End With
------

How can I set the index to -1 after i delete ?
if i only have 1 row in ListView, by adjusting index to -1 will still face
the problem since there is no record.

Pls guide
 
If you allow only one item to be selected you can use this line:
If (ListView1.SelectedItems.Count > 0) Then
ListView1.SelectedItems(0).Remove()
End If
 
if listview only got one row, after i have deleted that row, where should i
set my index ?? and how should i set my index...

thanks you
 
After you have deleted your selected row (last row), the index:
listView1.SelectedIndices(0)
Will be set automatically to -1 becasause no record is selected.
 
yes....when there is no record selected, then when i trigger
listview1.focuseditem.text then i will encounter problem....

after i delete my last row record, the system always trigger the event
listview1.selectedindexchanged, under that i got coding like
listiview1.focuseditem.text, so i will have problem

how could i avoid that...

when no record is being selected, then i dun want to trigger that
listview1.focuseditem.text

thank you
 
If I understand you correctly, you have code in the SelectedIndexChanged
event handler that assumes there is always a selected/focused item; if that
is the case simply check if indeed there is a selected item and return if
there isn't, e.g.:

'// in SelectedIndexChangedEvent make this the first line
If (ListView1.SelectedItems.Count = 0) Then Return

Cheers
Daniel
 
Then just add this line in the SelectedIndexChanged sub as the first line:
If (listView1.SelectedItems.Count = 0) Then Exit Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top