Here is some code that refreshes a DataGridView with a filtered/sorted list. It assumes you have a DataGridView object and you simply need to assign a filtered list to it.
Sorry about the formatting/double space... I can't figure out how to get code to look nice in here!
/// <summary>/// RefreshGrid gets an InventoryAssignmentList and filters/sorts the list
/// then sets the grid DataSource. /// </summary> private void RefreshGrid(){
InventoryAssignmentList.InvalidateCache(); // get the list of all InventoryAssignment objects InventoryAssignmentList list = InventoryAssignmentList.GetList(); // create the filter objectCsla.
FilteredBindingList<InventoryAssignment> filteredList = new Csla.FilteredBindingList<InventoryAssignment>(list); // get the categoryID we want to filter on int catID = GetSelectedCategoryIDInTree(); // apply the filter based on the property CategoryId if (catID > 0)filteredList.ApplyFilter(
"CategoryId", catID); // create a SortedBindingList with our filteredListCsla.
SortedBindingList<InventoryAssignment> sortedList = new Csla.SortedBindingList<InventoryAssignment>(filteredList); // apply the sort based on TypeName propertysortedList.ApplySort(
"TypeName", ListSortDirection.Ascending); // apply the filtered/sorted list to the DataGridView.DataSourceinventoryAssignmentListBindingSource.DataSource = sortedList;
inventoryAssignmentListBindingSource.ResetBindings(false);}
Copyright (c) Marimer LLC