CollectionBase problem

G

Guest

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...
 
D

Dan Bass

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...
 
J

Josema

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....
 

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