473,387 Members | 1,455 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

CollectionBase problem

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
2 1242
> 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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: m. pollack | last post by:
Hi all, I've been using the CollectionBase class to implement a strongly-typed collection, but I have noticed that the RemoveAt method does not seem to call the "On" hook methods (OnRemove,...
2
by: m.pollack | last post by:
Hi all, I have an application which uses a class object that contains a collection. In order to use the PropertyGrid control to expose properties to the user at runtime, I created a...
7
by: m. pollack | last post by:
Hi all, I've been using the CollectionBase class to implement a strongly-typed collection, but I have noticed that the RemoveAt method does not seem to call the "On" hook methods (OnRemove,...
2
by: m.pollack | last post by:
Hi all, I have an application which uses a class object that contains a collection. In order to use the PropertyGrid control to expose properties to the user at runtime, I created a...
0
by: LIJO CHEERAN | last post by:
Hello friends I am trying to study about CollectionBase. I have inherited CollectionBase in the class TheCollection.cs. I am using the “TheCollection. in an aspx page to store objects...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.