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

CollectionBase problem

P: n/a
Hi,

i have a windows application.

This application uses a object that its of type collectionbase.

For other hand i have a ListBox, and i use this collection to fill it.

I have implemented the methods (in my class that derives from collection
base):

//to get an element from collection
public type of object Get_(int index)
{
return (type of object) List[index]
}
//to add into collection
public void Add_(type of the object object)
{
List.Add(object)
}
//to remove from collection
public void Remove_(type of the object object)
{
List.Remove(object)
}
I dont know if my steps are correctly:

1) when application loads i fill the collection, and i fill the listbox with
the collection.
2) When a person clicks in a item i get the object from the collection with
the index (ListBox.SelectedIndex)
3) i remove from collection this object that i got in the step 2.
4) i assign the datasource of the listbox to null
5) i remove from the listbox the item selected
6) i assign the datasource of the listbox the collection (with the item
removed in step 3)

When i execute the application, and i delete an item, all goes correctly
except when i delete the last.... In this case (deleting the last item) the
application deletes it, but when i selected another item, i get an Error of
type IndexOutOfRange exception....

Questions:
1) What could be the problem?
2) Its my logic to do this wrong?
3) Generally this kind of stuff are made following this way?

Any advice would be appreciated...
--------
Thanks
Regards.
Josema
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
> When i execute the application, and i delete an item, all goes correctly
except when i delete the last.... In this case (deleting the last item)
the
application deletes it, but when i selected another item, i get an Error
of
type IndexOutOfRange exception....


How is this possible?
If you delete the last item, how can you select another item?
There's nothing to select...
Nov 16 '05 #2

P: n/a
Hi Dan,

Thanks for you early response, and sorry for my bad explanation...

My problem is, 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)...

Why doesnt work if i select the last item?

Thanks and sorry for my last bad explanation....


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.