By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,899 Members | 1,350 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,899 IT Pros & Developers. It's quick & easy.

ListBox with collection

P: n/a
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...

--
Thanks
Regards.
Josema
Nov 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

"Josema" <Je******@ocu.org> wrote in message
news:4D**********************************@microsof t.com...
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...

--
Thanks
Regards.
Josema

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.