This example illustrates how to filter a ListView displayed in a DashboardView based on another ListView's selection.
Scenario
When a DashboardView contains several list views, it is often required to make them dependent, e.g. display items of one ListView based on items or selection of another ListView.
Steps to implement
1. Add a new ViewController to your platform-agnostic module (DashboardFilterController).
2. In the OnActivated method retrieve the necessary DashboardViewItems via the FindItem method. After that subscribe to the ControlCreated event of the DashboardViewItem whose ListView will be used for filtering (hereinafter referred to as SourceView).
3. In the ControlCreated event handler retrieve the SourceView via the DashboardViewItem.InnerView property and subscribe to its SelectionChanged event.
4. In the SelectionChanged event handler retrieve the View that will be filtered (hereinafter referred to as TargetView) in the same manner as in the previous step.
5. To retrieve an object by which filtering will be performed, use the ListView.CurrentObject property. This object must be loaded from SourceView ObjectSpace to TargetView ObjectSpace via the GetObject method.
6. Now you can simply filter the TargetView by adding CriteriaOperator to the TargetView.CollectionSource.Criteria dictionary. In my example, I created a simple InOperator to filter the Position column via objects from SourceView.
Important notes:
The provided algorithm is platform-agnostic. It will work without any additional code in WinForms applications, but in ASP.NET the TargetView will not be refreshed immediately after changing the SourceView's selection. It is required to post changes made on the server side to the client to show them in the browser. That is why I have implemented the DashboardViewRefreshController that will refresh DashboardView when selection in the SourceView is changed. Handle the WebWindow.CurrentRequestWindow.PagePreRender event. In this event handler, find the ASPxGridView, modify its client-side SelectionChanged event and the script using the CallbackManager as shown in the DashboardRefreshController.cs file.
Then deactivate the WebRecordsNavigationController to prevent its activation for the TargetView in the DashboardView. This controller can lead to an exception during navigation to the record's DetailView on a clickin the SourceView. This behavior is caused by the fact that WebRecordsNavigationController lies inside the ListViewand collects information about records when this ListView is disposed of. It collects records based on visible rows, but since we filter the CollectionSource, it does not contain the required object.