Searchable and sortable binding list in CSLA?

Searchable and sortable binding list in CSLA?

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


rayc posted on Wednesday, June 20, 2007

I have a class that implements a searchable and sortable binding list (called SearchableSortableBindingList). When I bind such a list to a Datagridview, I get the ability to sort my records in ascending or descending order when I click a column header.

A few weeks later I discovered CSLA and started learning it. I belive in CSLA, you use BusinessListBase when you want a list of your business objects. However, this class does not have the functionality as in my SearchableSortableBindingList class.

Can someone explain to me how I can incorporate my class with CSLA? Or point me in the right direction?

Thanks !

Ray

 

JonM replied on Wednesday, June 20, 2007

You want to use the SortedBindingList.  Basically you create it and pass in your BusinessBase Collection.  Then you bind the SortedBindingList to the datagridview and now it is sortable!

 

JoeFallon1 replied on Wednesday, June 20, 2007

You can use SortedBindingList and/or FilteredBindingList if you only need single property sorting.

I decided to use the excellent ObjectListView (in CSLA Contrib) because it allows sorting and filtering in the same class with multiple property sorts as an option. Very easy to use.

Bottom line - Rocky decided that modifying the existing List was a bad idea and changed it in CSLA2 so that you can View the list instead. All 3 classes mentioned above support this view concept.

Joe

 

rayc replied on Friday, June 22, 2007

I can't seem to find ObjectListView.

Can you tell me where I can find it?

Thanks !

 

JoeFallon1 replied on Saturday, June 23, 2007

rayc:

I can't seem to find ObjectListView.

Can you tell me where I can find it?

Thanks !

This thread discusses it:

http://forums.lhotka.net/forums/thread/10559.aspx

Code can be found here:

http://www.codeplex.com/CSLAcontrib/SourceControl/ListDownloadableCommits.aspx
Go there and download the most recent version.  You should be able to find the necessary files in there.Extract the zip file into folders and delete all the stuff you don't want and keep:

\Csla2Extensions\ObjectListView\CSharp

I copied them to a new folder structure and created a separate project so I could reference the binaries in my real app. It also allowed me to change the namespace to Csla2 the other day and re-compile. I normally like to convert C# to VB but there is a lot of code here and it is fully tested - I would be afraid of introducing a bug. Brian said he was thinking of doing the conversion but it is a lot of work and not really needed as long as you can reference the binaries.

Joe

 

 

rayc replied on Thursday, June 21, 2007

From Rocky's book I have the following:

public class InvoiceList : ReadOnlyListBase<InvoiceList, InvoiceInfo>
{
   
public static InvoiceList GetInvoiceList()
        {
           return DataPortal.Fetch<InvoiceList>(new Criteria());
        }
...

}

So I modified it to look like this:

public static InvoiceList GetInvoiceList()
        {
     InvoiceList _invoiceList = DataPortal.Fetch<InvoiceList>(new Criteria());
     SortedBindingList<InvoiceList> sortedList = new SortedBindingList<InvoiceList>(_invoiceList);
            return sortedList;
        }

The problem I'm having is that I'm trying to take the list returned by the DataPortal.Fetch and converting it to a SortedBindingList.

But this doesn't work. The compiler isn't able to convert from one to the other. What am doing wrong?

Thanks in advance

 

Brian Criswell replied on Thursday, June 21, 2007

Either do this:

public static SortedBindingList<Invoice> GetSortedInvoiceList()
{
    InvoiceList _invoiceList = DataPortal.Fetch<InvoiceList>(new Criteria());
    SortedBindingList<Invoice> sortedList = new  SortedBindingList<Invoice>(_invoiceList);
    return sortedList;
}


or this:

SortedBindingList<Invoice> sortedList = new  SortedBindingList<Invoice>(InvoiceList.GetInvoiceList());

rayc replied on Friday, June 22, 2007

I had tried that but I kept getting error CS1502:

The best overloaded method match for Csla.SortedBindingList<Accounting.Invoice>.SortedBindingList<System.Collections.Generic.IList<Accounting.Invoice>> has some invalid arguments

The same line also gives me the error CS1503:
Argument '1' cannot convert from 'Accounting.InvoiceList' to 'System.Collections.Generic.IList<Accounting.Invoice'

 

Brian Criswell replied on Wednesday, June 20, 2007

CSLA comes with two views, FilteredBindingList and SortedBindingList that allow you to filter or sort a list of objects.  They are composable, so you can add a list to a SortedBindingList and then add that to a FilteredBindingList.

Alternatively, you can use the ObjectListView from the CSLAcontrib project. It follows the same semantics as the System.Data.DataView but works on lists of objects.

Copyright (c) Marimer LLC