ListBox with collection

G

Guest

Hi,
My problem is the next one (in a windows application):
- I have a class derived from collectionbase to fill with persons object
(id, name) from database.
- I have a ListBox wich datasource its the collectionbase above.

I want to do:
- I would like that when i click in a item of the listbox, deletes from
database the values of this item, and from collection too. Then refresh the
listbox with the collection modified.

My situation:
- I select a item from ListBox, then delete from database
the ID of the Item in database, then i delete the selectedindex from
collection of objects, and then i clear the items from the listbox and i
assign again the datasource to the collection (with the object
removed)...

My problem:
- The program works, except if select the last item to remove. In this case
the item is well removed, but when i will selected another item of the
listbox, i get an IndexOutOfRange exception...
 
D

DalePres

There's not much to go on, no sample code, etc. but you might try this.
Before deleting the item from the collection test to see if the
collection.Count is 1. If you know you are deleting the last item, then
before deleting it, try ListBox.Items.Clear() before deleting the last item
from the collection.

HTH

DalePres
 

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

Top