How do I implement a sortable EditableRootListBase?

How do I implement a sortable EditableRootListBase?

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


andrewrajcoomar posted on Wednesday, January 21, 2009

Hello,

Can anyone give me some pointers or an  example on how to implement a sortable dynamic list using editablerootlistbase class? Prior to using the ERLB, I was implementing a sortable list (where objectList inherits from readonlylistbase) like this:

objectListBindingSource.DataSource = New SortedBindingList(Of objectInfo)(objectList)

Thanks,

Andrew

andrewrajcoomar replied on Wednesday, January 21, 2009

I am guessing this is not possible!

tiago replied on Monday, January 26, 2009

Well... in fact it is possible. Take a BrandColl ERLB made of Brand root objects:

Attach the BindingSource to the DataGridView

 

brandCollDGV.DataSource = brandCollBindingSource;

 

Now make the sorted list

 

_thisBrandColl = BrandColl.GetBrandColl();

brandCollBindingSource.RaiseListChangedEvents = false;

var sortedList = new SortedBindingList<Brand>(_thisBrandColl);

sortedList.ApplySort("BrandName", ListSortDirection.Ascending);

brandCollBindingSource.DataSource = sortedList;

brandCollBindingSource.RaiseListChangedEvents = true;

brandCollBindingSource.ResetBindings(false);

andrewrajcoomar replied on Tuesday, January 27, 2009

I'll be damn. Makes sense now as they all implemet IList(Of T).

Thanks,

Copyright (c) Marimer LLC