How do you sort a ReadOnlyListBase?

How do you sort a ReadOnlyListBase?

Old forum URL: forums.lhotka.net/forums/t/1095.aspx


bradygaster posted on Thursday, August 31, 2006

Is it possible to do this? I've looked through the forums and was only able to find one very confusing thread that alluded to there being no simplistic method of providing sort capabilities to a ReadOnlyListBase implementation. The implementation discussed, like mine, was relevant to a web application, but it appeared to be a relatively convoluted solution (forgive the strong opinion). Am I wrong in assuming that I'll have to create a whole new class to sort? And that the ReadOnlyListBase class fails to provide this functionality? Please help!

Brian Criswell replied on Thursday, August 31, 2006

The BusinessBase and BusinessCollectionBase in 1.x did have sort functionality, but it made the classes very complex when combined with n-level undo.

In 2.x, BusinessBase and BusinessListBase do not have sort functionality.  Rocky has provided SortedListBase and FilteredListBase to provide sorting and filtering, respectively.  They are relatively simple to use.  I have also provided a class called ObjectListView to the CSLA community through the CodePlex site.  It behaves similarly to a DataView for any object that implements IList.  You can sort and filter through it, and it also has the ability to include a default item as the first item in its list.  Instructions on how to use either set of classes can be found by searching the forums.

JoeFallon1 replied on Thursday, August 31, 2006

Brian,

I am just looking in to Sorting and Filtering. The 1.x SortableCollectionBase developed by Tim and Tom was very powerful. It had 2 great features - one was StableSort and the other was SortMulti.

I discovered that sorting could re-arrange "ties" and this caused all sorts of bugs in a Web page grid when trying to identify which row was selected. (The BO would re-sort and the index no longer found the selected item!)

SortMulti was useful for sorting on more than 1 column at a time. You just create a paramarray of SortParm objects and it worked great.

I know that Rocky's SortedBindingList only sorts on a single Property. Does you ObjectListView allow sorting on more than 1 Property?

Does anyone know if there are plans to implement multi-field sorting in Rocky's SortedBindingList? Does someone have the knowledge/skills to do this on their own? (Tim - where are you?)

Finally, does anyone know if there are issues with unstable sorting associated with Rocky's SortedBindingList?

Thanks.

Joe

 

 

 

 

 

Brian Criswell replied on Friday, September 01, 2006

Hi Joe,

The ObjectListView implements IBindingListView, the same interface supported by DataView and BindingSource.  This interface provides multi-column sorting.  I have also put a lot of effort into making the  ObjectListView do a stable sort even over multiple columns.  I have not had much opportunity to test multi-column sorting however.  I would suggest that you give it a go and see if it does what you need.

Regards,
Brian

bradygaster replied on Friday, September 01, 2006

In my case, all I'll need to do is single-column sorting. Right now all I have is a ReadOnlyListBase. I just need some sample code (please don't redirect me to another forum post, I've scoured the forums and haven't found anything, least not anything concise) to demonstrate how a ReadOnlyListBase can either be sorted or be used to create another list that can be sorted?

Why, oh why, does everything in CSLA have to be so complicated? I was under the impression this framework was supposed to make a developer's life easier!

ajj3085 replied on Friday, September 01, 2006

Brady,

Its not as complicated as you think.  If your UI code, you do this:

private void Form_Load( object sender, EventArgs e ) {
    // myRO is your ReadOnlyBase subclass, which is contained
    // in the myROList collection class, which is your ReadOnlyListBase subclass.
    myBindingSource.DataSource = new SortedBindingList<myRO>( myROList );
}

Csla is complex because it takes care of many of the details for you, but once you learn how to use the framework properly, you'll see it DOES make things much easier for you.  But you do have to invest time to learn the framework... get the book if you haven't already.  This will go a long, long way to helping you understand how the framework works and show you want it does (and doesn't) do for you.

bradygaster replied on Friday, September 01, 2006

Thanks so much for that excellent code sample. By the time I'd received it I'd come up with a solution very similar to that which you pointed out herein. Thanks a lot.

PS - I've shortened this 3 or 4 times, and tried to clean it up a little. Let me just save everyone the trouble and frustrations by stipulating that "buying the book" seems a far-fetched notion. It seems like a huge expectation that will prohibit growth of the CSLA framework rather than extend it. Especially considering the nature of software development - iterative releases - why force us to buy a book over and over again when there is so much information out there? Make the info more readily available in the form of step-by-step examples. OneLittleVictory.com is a great place to begin, but when you get into the specificity, like sorting/filtering, and so on, there needs to be a more definitive resource.

ajj3085 replied on Friday, September 01, 2006

Csla exists because Rocky writes books about building business object frameworks.  The fact that we end up with a complete, usable framework is just a happy side effect. 

As he said, "the framework is a maketing tool for the book," not the other way around..

tetranz replied on Friday, September 01, 2006

bradygaster:
Let me just save everyone the trouble and frustrations by stipulating that "buying the book" seems a far-fetched notion. It seems like a huge expectation that will prohibit growth of the CSLA framework rather than extend it.

I really don't think you'll find much support for that viewpoint. I obviously can't speak for Rocky but I gather that his real focus is on education and encouraging best practices to the .NET community. In a sense, CSLA is just a very useful example of the concepts and techniques presented in the book.

In a practical sense, I assume the book is also the only direct financial reward Rocky gets from the many hours of work he has put into CSLA so unless your circumstances make the buying the book difficult, I would encourage you to do so. The book(s) has a lot of great stuff even if you don't end up using CSLA.

Ross

david.wendelken replied on Friday, September 01, 2006

bradygaster:
Let me just save everyone the trouble and frustrations by stipulating that "buying the book" seems a far-fetched notion. It seems like a huge expectation that will prohibit growth of the CSLA framework rather than extend it.

Frankly, this framework is a steal at $40 for a book that explains it. 

bradygaster:
why force us to buy a book over and over again when there is so much information out there? Make the info more readily available in the form of step-by-step examples. OneLittleVictory.com is a great place to begin, but when you get into the specificity, like sorting/filtering, and so on, there needs to be a more definitive resource.

Well, Rocky has a day job already, and a family, and he's produced a framework and a multiple books explaining it, and he spends time on this list answering questions.  There are only 24 hours in a day - when is he supposed to do all this additional work?  We aren't talking about MicroSoft and huge teams of developers here - just one person!

Write some step-by-step examples as you learn it and share them with the rest of us. :)

He is planning on selling new chapters to his book in electronic format, so you can just buy the "new" material explaining the framework changes.   I think that's a great idea.

FireGarden replied on Friday, September 01, 2006

Kick him off the forum until he buys at least 2 copies of the book!!!

Viva Rocky!!!

simon_may replied on Friday, September 01, 2006

 Let me just save everyone the trouble and frustrations by stipulating that "buying the book" seems a far-fetched notion. It seems like a huge expectation that will prohibit growth of the CSLA framework rather than extend it. Especially considering the nature of software development - iterative releases - why force us to buy a book over and over again when there is so much information out there? Make the info more readily available in the form of step-by-step examples.

 

Some people just don't see when they are on to a good thing. I suggest you do a cost benefit exercise on comparable coftware. available through commercial channels. The book, its previous incarnations, this forum and the people and the time and information they contrbute to it is highly impresive and a great testement to the endevour of Rocky. Buying his book from time to time is no burden at all.

bradygaster replied on Friday, September 01, 2006

I think people have taken me a little out of context, so let me try to explain some of the points I was making. Not in defense of myself, but in defense of my esteemed collague Rocky, who I have no intent on insulting or defaming. Nothing even close, actually.

Points all well taken, sirs (or/and madams). My honest bet from experience is that Rocky gets far, FAR less money from the renumeration on his books than he deserves. The framework itself and the postulations put forth in its implementation are far superior for certain characteristics of enterprise programming. Especially when one considers the excellent support resident in it for remoting. My personal feeling is that there is a good deal too much focus on the notion of remoting and that there are quite a few extraneous classes througout the framework itself. I'd love to see a remoting-independent version for those of us who aren't implementing such a solution.

I still believe that the requirment of buying the book is a little hard to swallow. There are many ORM and non-ORM enterprise models out there, and they're heavily documented on the internet. It seems there is such little documentation for the CSLA framework outside of the books focusing on it. To me, the lack of non-"published" data is a terrible thing - the OneLittleVictory.com tutorial is an excellent introduction to the framework, but barely scratches the surface of what is possible. My point was to stress the need  for more in-depth knowledge outside of the book itself. To me it seems a little trite that the single most definitive resource on Rocky's excellent implementation is in a book, and that the web lacks so much neccessary information.

And as someone who also has a family, who has written, and who has contracted, I feel a great deal of gratitude and comraderie for Rocky; those books have most likely paid for a meager amount of the effort he's put forth, especially in contrast to what (I'm guessing) the guy makes in his contractual life. His efforts are far more widespread and appreciated than the vast majority of us, and I for one owe him a debt of gratitude for the extensiveness of this framework and intended no harm whatsoever in any of my reviews. Simply, it wasn't obvious how to accomplish certain things that seem so obvious in other similar frameworks.

Thanks so much for your help in this particular technical matter, and for the engaging conversation. Hopefully next time I'll explain myself a little more clearly!

ajj3085 replied on Friday, September 01, 2006

bradygaster:
My personal feeling is that there is a good deal too much focus on the notion of remoting and that there are quite a few extraneous classes througout the framework itself. I'd love to see a remoting-independent version for those of us who aren't implementing such a solution.


Well, considering that the remoting is there to provide Scalability (the S in Csla), I think its important to cover.  Even if you never plan to use remoting, coding through the dataportal is relatively simple and a good idea because its a way to keep your data access code isolated (which logically seperates the business layer from the data layer.. or the L in Csla).

bradygaster:
I still believe that the requirment of buying the book is a little hard to swallow. There are many ORM and non-ORM enterprise models out there, and they're heavily documented on the internet. It seems there is such little documentation for the CSLA framework outside of the books focusing on it.


Those projects exist because some people decide to dedicate their time for free, or their employer pays them to work on an 'open source' project.  That is not why Csla exists though.  Csla is an example framework to put concrete implementation on the ideas discussed in the book.

bradygaster:
To me, the lack of non-"published" data is a terrible thing - the OneLittleVictory.com tutorial is an excellent introduction to the framework, but barely scratches the surface of what is possible. My point was to stress the need  for more in-depth knowledge outside of the book itself. To me it seems a little trite that the single most definitive resource on Rocky's excellent implementation is in a book, and that the web lacks so much neccessary information.


Well, lets assume all the detailed info you needed was here or other places on the web.  What instentives now are there to buy his book? 

bradygaster:
And as someone who also has a family, who has written, and who has contracted, I feel a great deal of gratitude and comraderie for Rocky; those books have most likely paid for a meager amount of the effort he's put forth, especially in contrast to what (I'm guessing) the guy makes in his contractual life. His efforts are far more widespread and appreciated than the vast majority of us, and I for one owe him a debt of gratitude for the extensiveness of this framework and intended no harm whatsoever in any of my reviews. Simply, it wasn't obvious how to accomplish certain things that seem so obvious in other similar frameworks.


I assume if Rocky wasn't getting the return he wanted on the books he would find another way to support himself, to the community's loss.  If you had read the book, the answer to your question would have been obvious.  Remember, the framework is Rocky's marketing for his book.. so he quite rightly points you to chapters which contain the answers to common questions.

To be fair, I'm not sure there are many frameworks out there at all that discuss in as much depth the reasoning behind the design of framework.  For me, knowing WHY the framework was put together a certain way makes it worlds easier to use.

Currently, I'm muddling through the Composite UI Application Block; I'd love to have a book detailing why that framework is built as it is.. but at the moment, it doesn't seem to me why all the overhead is worth it, not the mention the amount of code I'd have to write for UI controls.. which admittedly isn't my strong point.  Off topic, if anyone has such a text on the CAB, I'd love to see it, as I believe understanding the CAB will be key to understanding WPF.

Michael Hildner replied on Friday, September 01, 2006

I know I shouldn't be fueling this thread, but my curiosity has gotten the best of me... So I have to ask.

>>I still believe that the requirment of buying the book is a little hard to swallow.

I'm incredibly curious as to what the burden is - for you or anyone else. I mean, is it the financial cost? The availability of the book? Maybe you prefer bytes over atoms (having the info digitally rather than in a physical book)? The learning curve? Something else?

The only reason I'm asking is that if there are any burdens to learning/using CSLA, I think those issues could be addressed.

david.wendelken replied on Friday, September 01, 2006

ajj3085:


Its not as complicated as you think.  If your UI code, you do this:

private void Form_Load( object sender, EventArgs e ) {
    // myRO is your ReadOnlyBase subclass, which is contained
    // in the myROList collection class, which is your ReadOnlyListBase subclass.
    myBindingSource.DataSource = new SortedBindingList<myRO>( myROList );
}

It's not always that easy either.  If you put the SortedBindingList in a Session["someCache"] variable, your UI control will work fine.  But, if you have an event handler that should activate a method in your class, you won't be able to do that against the SortedBindingList.  You will have to also store the collection object in another session variable.  And, if you are also wanting to use paging and the UI control doesn't do it for you automagically, you may need to use PagedDataSource, which introduces a third collection to store in the session variables.  (Unless you like re-sorting large lists of data every time you do a post-back.)

I've gotten all three to work together, but still haven't worked out a way that I like.  Still seems too kludgy to me.

ajj3085:

Csla is complex because it takes care of many of the details for you, but once you learn how to use the framework properly, you'll see it DOES make things much easier for you.  But you do have to invest time to learn the framework... get the book if you haven't already.  This will go a long, long way to helping you understand how the framework works and show you want it does (and doesn't) do for you.

Despite my frustration on this one issue, I am very happy with my use of Csla.  It is a very nice, very productive framework.  And yes, the book is well worth the investment.

Copyright (c) Marimer LLC