Filtering a WPF ListBox

Filtering a WPF ListBox

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


Brad posted on Wednesday, January 14, 2009

Greetings,

I am using a CslaDataProvider to get back a read only list of business objects. This list of objects is bound to a listbox. I would like to filter these business objects based on text in a textbox on the view.

I've tried the method discussed on the following blog post (http://blogs.vertigo.com/personal/alanl/Blog/archive/2008/02/04/wpf-how-to-filter-listbox-items-on-the-fly.aspx) but it does not work with CSLA collections - it throws a NotSupportedException.

How do you dynamically filter a ReadOnlyList that is retrieved via a CslaDataProvider?

Cheers,
-Brad

sergeyb replied on Wednesday, January 14, 2009

I simply use Linq in my application, and bind the listbox to a result of a query using a public method in ROLB class instead of binding the listbox directly to ROLB. On textchange I fire this method again to refresh the UI.

Sergey Barskiy
Principal Consultant
office: 678.405.0687 | mobile: 404.388.1899

Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

-----Original Message-----
From: Brad [mailto:cslanet@lhotka.net]
Sent: Wednesday, January 14, 2009 9:01 PM
To: Sergey Barskiy
Subject: [CSLA .NET] Filtering a WPF ListBox

Greetings,

I am using a CslaDataProvider to get back a read only list of business objects. This list of objects is bound to a listbox. I would like to filter these business objects based on text in a textbox on the view.

I've tried the method discussed on the following blog post (http://blogs.vertigo.com/personal/alanl/Blog/archive/2008/02/04/wpf-how-to-filter-listbox-items-on-the-fly.aspx) but it does not work with CSLA collections - it throws a NotSupportedException.

How do you dynamically filter a ReadOnlyList that is retrieved via a CslaDataProvider?

Cheers,
-Brad

rfcdejong replied on Friday, January 16, 2009

The CslaDataProvider is inheriting the DataSourceProvider which is a differend one then ObjectDataProvider (it used to be "ObjectDataSource" in the past).
The ObjectDataProvider is just inheriting the DataSourceProvider as well and adds extra functionality. All that extra functionality that the ObjectDataProvider adds isn't available in the CslaDataProvider.

Anyway u can dynamically filter using the CslaDataProvider FactoryParameters which will result into a new query being executed. Just databind the FactoryParameters to the control :)

PS: See page 611 in the 3.6 CSLA book for an example.

Copyright (c) Marimer LLC