473,383 Members | 1,829 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,383 software developers and data experts.

Sortable collection

_DS
I understand that the usual way of creating a strongly typed
collection is to inherit from CollectionBase. However, CollectionBase
does not support sorting. What is the best way to implement this?
Derive from ArrayList?

Jan 29 '06 #1
10 5170
_DS <_D*@Nospamforme.com> wrote:
I understand that the usual way of creating a strongly typed
collection is to inherit from CollectionBase. However, CollectionBase
does not support sorting. What is the best way to implement this?
Derive from ArrayList?


CollectionBase.InnerList returns an ArrayList, so you can sort that.

Of course, in 2.0 you probably wouldn't use CollectionBase in the first
place, but List<T>.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 29 '06 #2
"_DS" <_D*@Nospamforme.com> wrote in message
news:6q********************************@4ax.com...
I understand that the usual way of creating a strongly typed
collection is to inherit from CollectionBase. However, CollectionBase
does not support sorting. What is the best way to implement this?
Derive from ArrayList?


I honestly do not understand the thinking process of some people who post on
these groups.

This is how I would think:

1) I want to implement a strongly typed collection so I use CollectionBase
2) What does CollectionBase give me to help implement this? Oh. there's this
protected property called InnerList which gives access to the ArrayList used
to implement the collection.
3) I will implement Sort by calling InnerList.Sort()

I can't see how it could be any easier.
The hardest part is finding CollectionBase in the first place and even that
comes naturally from saying to yourself "I want to do collection stuff so
what is in the Collections namespace?"

I don't like to flame but RTFM dude - 99 times out of a 100 its quicker than
posting and you learn extra stuff beyond your particular problem of the
moment.

Jan 29 '06 #3
If you don't like to flame, then why do it?
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Nick Hounsome" wrote:
"_DS" <_D*@Nospamforme.com> wrote in message
news:6q********************************@4ax.com...
I understand that the usual way of creating a strongly typed
collection is to inherit from CollectionBase. However, CollectionBase
does not support sorting. What is the best way to implement this?
Derive from ArrayList?


I honestly do not understand the thinking process of some people who post on
these groups.

This is how I would think:

1) I want to implement a strongly typed collection so I use CollectionBase
2) What does CollectionBase give me to help implement this? Oh. there's this
protected property called InnerList which gives access to the ArrayList used
to implement the collection.
3) I will implement Sort by calling InnerList.Sort()

I can't see how it could be any easier.
The hardest part is finding CollectionBase in the first place and even that
comes naturally from saying to yourself "I want to do collection stuff so
what is in the Collections namespace?"

I don't like to flame but RTFM dude - 99 times out of a 100 its quicker than
posting and you learn extra stuff beyond your particular problem of the
moment.

Jan 30 '06 #4
_DS,

You will probably want to implement IComparable in the class for which you
are building the CollectionBase implementation - not in the collection but in
the class the collection will hold.

And there's nothing that says you couldn't then create your own Sort command
in your custom collection, but John is correct, there is one that you can use.

In either case, writing your own sort or using InnerList.Sort(), you should
implement IComparable so that the sort can do the comparisons that are
required.

HTH
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Jon Skeet [C# MVP]" wrote:
_DS <_D*@Nospamforme.com> wrote:
I understand that the usual way of creating a strongly typed
collection is to inherit from CollectionBase. However, CollectionBase
does not support sorting. What is the best way to implement this?
Derive from ArrayList?


CollectionBase.InnerList returns an ArrayList, so you can sort that.

Of course, in 2.0 you probably wouldn't use CollectionBase in the first
place, but List<T>.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Jan 30 '06 #5
Some suggested reading for you, Nick:

http://www.dalepreston.com/Blog/2005...by-insult.html

HTH
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Nick Hounsome" wrote:
"_DS" <_D*@Nospamforme.com> wrote in message
news:6q********************************@4ax.com...
I understand that the usual way of creating a strongly typed
collection is to inherit from CollectionBase. However, CollectionBase
does not support sorting. What is the best way to implement this?
Derive from ArrayList?


I honestly do not understand the thinking process of some people who post on
these groups.

This is how I would think:

1) I want to implement a strongly typed collection so I use CollectionBase
2) What does CollectionBase give me to help implement this? Oh. there's this
protected property called InnerList which gives access to the ArrayList used
to implement the collection.
3) I will implement Sort by calling InnerList.Sort()

I can't see how it could be any easier.
The hardest part is finding CollectionBase in the first place and even that
comes naturally from saying to yourself "I want to do collection stuff so
what is in the Collections namespace?"

I don't like to flame but RTFM dude - 99 times out of a 100 its quicker than
posting and you learn extra stuff beyond your particular problem of the
moment.

Jan 30 '06 #6
One RTFM at the end of a post containing the answer to his question plus the
constructive advice about how to go about answering future questions hardly
constitutes motivation by insult.

Surely you must agree that to post without even looking up the members of
the class you are using indicates either laziness or poor problem solving
skills.

"Dale" <da******@nospam.nospam> wrote in message
news:AE**********************************@microsof t.com...
Some suggested reading for you, Nick:

http://www.dalepreston.com/Blog/2005...by-insult.html

HTH
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Nick Hounsome" wrote:
"_DS" <_D*@Nospamforme.com> wrote in message
news:6q********************************@4ax.com...
>I understand that the usual way of creating a strongly typed
> collection is to inherit from CollectionBase. However, CollectionBase
> does not support sorting. What is the best way to implement this?
> Derive from ArrayList?


I honestly do not understand the thinking process of some people who post
on
these groups.

This is how I would think:

1) I want to implement a strongly typed collection so I use
CollectionBase
2) What does CollectionBase give me to help implement this? Oh. there's
this
protected property called InnerList which gives access to the ArrayList
used
to implement the collection.
3) I will implement Sort by calling InnerList.Sort()

I can't see how it could be any easier.
The hardest part is finding CollectionBase in the first place and even
that
comes naturally from saying to yourself "I want to do collection stuff so
what is in the Collections namespace?"

I don't like to flame but RTFM dude - 99 times out of a 100 its quicker
than
posting and you learn extra stuff beyond your particular problem of the
moment.

Jan 30 '06 #7
_DS
On Sun, 29 Jan 2006 08:00:46 GMT, "Nick Hounsome"
I honestly do not understand the thinking process of some people who post on
these groups.


Here's my thinking process: You should find those guys who beat you
up on the playground and give them a good scolding. I do want to
thank you for my heightened appreciation for the Dale Prestons and
John Skeets of the world. Usenet would be a sorry place...

Dale and John, thanks again. I'll eventually move to generics, but I
had already written a class that derived from ArrayList and
implemented compare functions, etc. I was going to change to derive
from CollectionBase instead. I did miss the InnerList property,
partly as I was looking for functions. But more because I thought
that CollectionBase was further down in the inheritance hierarchy and
that ArrayList was derived from CollectionBase. I'll check into that.

Jan 31 '06 #8

"_DS" <_D*@Nospamforme.com> wrote in message
news:1j********************************@4ax.com...
On Sun, 29 Jan 2006 08:00:46 GMT, "Nick Hounsome"
I honestly do not understand the thinking process of some people who post
on
these groups.
Here's my thinking process: You should find those guys who beat you
up on the playground and give them a good scolding. I do want to
thank you for my heightened appreciation for the Dale Prestons and
John Skeets of the world. Usenet would be a sorry place...


Hypocrit! This is way more of a flame than I dished out.

Dale and John, thanks again. I'll eventually move to generics, but I
had already written a class that derived from ArrayList and
implemented compare functions, etc. I was going to change to derive
from CollectionBase instead. I did miss the InnerList property,
partly as I was looking for functions.
Hopefully thanks to my comment you have now learned to look for protected
properties.
But more because I thought
that CollectionBase was further down in the inheritance hierarchy and
that ArrayList was derived from CollectionBase.


Why? Inheritance is shown quite clearly near the top of the doc page.

You are just proving my point that a few moments careful reading of the
documentation about a class is more time efficient than posting.
Jan 31 '06 #9
_DS
On Tue, 31 Jan 2006 08:09:33 GMT, "Nick Hounsome"
<nh***@nickhounsome.me.uk> wrote:
"_DS" <_D*@Nospamforme.com> wrote in message
news:1j********************************@4ax.com.. .
On Sun, 29 Jan 2006 08:00:46 GMT, "Nick Hounsome"
I honestly do not understand the thinking process of some people who post
on
these groups.
Here's my thinking process: You should find those guys who beat you
up on the playground and give them a good scolding. I do want to
thank you for my heightened appreciation for the Dale Prestons and
John Skeets of the world. Usenet would be a sorry place...


Hypocrit! This is way more of a flame than I dished out.


More of a flame than your "Read The Fucking Manual" rant? (or did you
not know what RTFM means). You can dish it out, I'll give you that.
Hopefully thanks to my comment you have now learned to look for protected
properties.


Hopefully you'll try decaf. In the future, consider what you're
saying and please don't 'Help" me any more. I thought this group was
relatively free of flamers.

DS
Feb 4 '06 #10

"_DS" <_D*@nomail.com> wrote in message news:8f********************************@4ax.com...
On Tue, 31 Jan 2006 08:09:33 GMT, "Nick Hounsome"
<nh***@nickhounsome.me.uk> wrote:
"_DS" <_D*@Nospamforme.com> wrote in message
news:1j********************************@4ax.com. .. <snip>Hypocrit! This is way more of a flame than I dished out.


More of a flame than your "Read The Fucking Manual" rant? (or did you
not know what RTFM means). You can dish it out, I'll give you that.


Perhaps he meant "Read the FINE Manual" and you just took it wrong?!?!

:^)

OK...I'll go away now

Bill
Feb 5 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: suz | last post by:
Hey, I have a collection with custom objects. That collection is bounded to a listview (I used the article of Lhotka). The listview is also sortable. I have also textboxes bound to the same...
0
by: cedoucette | last post by:
I just wrote code to support sortable columns in a datagrid. It seems to work fine; but, it doesn't look right. The problem is that I have a generic style for links and a different style for the...
2
by: Jon | last post by:
My application needs to present data generated at run time in a datagrid that can be sorted by clicking on columns, and where rows can be selected and events generated. Do I need to set up a...
4
by: Pieter | last post by:
Hi, I made a Collection-class that inherits from System.Collections.ObjectModel.Collection(Of T), but when I use this collection as a DataSource of a DataGrid or a DataGridView, it isn't sorted...
3
by: TPhelps | last post by:
I have a sample of an unbound (autogeneratecolumns is true) sortable/pagable datagrid that works. I want to change one of the columns to a hyperlink. The examples I find use a bound column. I...
1
by: vincemoon | last post by:
Sites such as download.com, dealtime.com, shopping.com, and tucows.com, feature impressive sortable lists of products. What software that imports CSV can be used to generate database-driven...
7
by: shellon | last post by:
Hi all: I want to convert the float number to sortable integer, like the function float2rawInt() in java, but I don't know the internal expression of float, appreciate your help!
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.