FilteredBindingList/ObjectListView implementation...

FilteredBindingList/ObjectListView implementation...

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


Mahmud posted on Saturday, May 12, 2007

In our gridview we have two combo boxes which will be in cascading effect - first one will show Prouct Type and the second one will show Product Name filtered by the selected type. I read the Windows Forms FAQ Article from Microsoft where they had one example with 'DataView and DataTable'. This will not work for us as we are using CSLA.

As much as I read from the newsgroup, I have to use FilteredBindingList or ObjectListView. But sorry to say that, I could not find any good example implementation. Can anyone help?

Its URGENT!

Brian Criswell replied on Saturday, May 12, 2007

There should be examples of FilteredBindingList in the CSLA 2.1 ebook that is available for purchase from Rocky's site.

The ObjectListView uses the same scheme as the DataView.  Assuming that you had a list of objects with the properties Id, Name and Active, you could create an ObjectListView that was sorted by Name and showed only the Active entries, you would do the following.

ObjectListView view = new ObjectListView(myList, "Name", "Active = True");

For your example, you would want to wrap your ProductList in an ObjectListView.
ObjectListView view = new ObjectListView(myList);
This would be the data source for your second combo box.  Handle the SelectedIndexChanged event on the first ComboBox and set the filter property on the view to the SelectedValue.

if (productTypeComboBox.SelectedValue == null)
{
    view.Filter = "1 = 2"; // Should hide everything because no product type is selected
}
else
{
    view.Filter = "ProductType = " + productTypeComboBox.SelectedValue.ToString();
}

The view will fire a ListChangedType.Reset which the second combo box will pick up and display the newly visible items.

Mahmud replied on Saturday, May 12, 2007

Thanks Brian. I have just downloaded CSLAContrib_14552. Is that the latest version of ObjectListView? I will use it and let you know if I face any problems...

Brian Criswell replied on Saturday, May 12, 2007

ObjectListView has not been modified for quite a while, so the latest version of CSLAcontrib will be fine.

Mahmud replied on Saturday, May 12, 2007

Great! It was a breeze to implement ObjectListView to do what I wanted. In terms of cascading combo inside gridview, I had to write code in CellBeginEdit and CellEndEdit events. Filtered the second combo from value selected in the first combo - in CellBeginEdit. Then resetting the ObjectListView filter in CellEndEdit event. To remove the filter I used Filter="", is this the correct method? I did not find any RemoveFilter() method.

 

 

Brian Criswell replied on Monday, May 14, 2007

Yes, that is the way to remove the filter.  I believe there is a RemoveFilter method on IBindingListView (which ObjectListView implements), so you could cast to IBindingListView, but it seems unnecessary, don't you think?

Anyway, I am glad you found it to be so easy.

Copyright (c) Marimer LLC