Best way to filter a listbox databound to a llblgen collection

Posts   
 
    
kal
User
Posts: 18
Joined: 25-May-2010
# Posted on: 06-Jul-2010 11:58:31   

Hi,

I have a collection of entities, let's say :

CustomersCollection costumersColl;

It's bounded to a listbox as DataSource.

I have a textbox to filter the elements in that listbox. Currently, the best way I've found to do this is to use two data tables : - DataTable dtOriginal -> Contains every entities in costumersColl and is bounded to the listbox as DataSource - DataTable dtCurrent -> is the result of a call to Select() to dtOriginal object. It's then bounded to the listbox. When the textbox search is cleared, I reset the data source of the listbox to dtOriginal.

Do you have any idea of a simpler/more efficient way in doing this ?

Regards, Kal

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 06-Jul-2010 20:34:56   

A better bet would be to create a DataView based on the datatable, and filter that instead. The dataview can then remain bound to the listbox without the need to keep rebinding different collections.

Matt

kal
User
Posts: 18
Joined: 25-May-2010
# Posted on: 06-Jul-2010 20:39:13   

MTrinder wrote:

A better bet would be to create a DataView based on the datatable, and filter that instead. The dataview can then remain bound to the listbox without the need to keep rebinding different collections.

Matt

Well, I've just found a way similar to your suggestion : I'm using a LLBLGen View (DefaultView property of a collection). Then I can set the Filter property of the view. I guess it's the simplest way to do this.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 06-Jul-2010 20:46:14   

Spot on...!

Matt