Implement Swap method for BusinessListBase

Implement Swap method for BusinessListBase

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


Cuong posted on Saturday, July 05, 2008

My application need to swap 2 child BOs in the BusinessListBase. In the CSLA 3.0 I use the snippet code bellow with success

void SwapItem(int i, int j)
{
            if  (i != j)
            {
                C temp = this.ItemsIdea [I];
                this.ItemsIdea [I] = this.Items[j];
                this.Items[j] = temp;
            }
}

But I see in CSLA 3.5 the code to Insert/Remove item is much more complicated because of Linq support. And maybe that above snippet code is not properly. Anyone has idea to implement Swap method for BusinessListBase?

JonStonecash replied on Saturday, July 05, 2008

This looks very much like you are sorting the list.  You might want to take a look at the CSLA SortedBindingList.  This is a wrapper class around the BusinessListBase<TList, TItem>.  You can control the sort order (which need not be a strict ascending or descending order).  This class can be used any where that the BusinessList class can be used.  You could inherit from SortedBindingList, add your swap functionality, and avoid adding and removing items from the list.

Jon Stonecash

Cuong replied on Sunday, July 06, 2008

Yes, the purpose of Swap method is to let user sort BusinessListBase manually. User can click Up/Down button to move selected items Up/Down. I just tried to use SortedBinddingList to implement the Swap method. This solution breaks a little bit of my previous app design but it fits my need. Thank you very much.

Copyright (c) Marimer LLC