Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

How to implement dependent views in a DashboardView (filter based on selection)

$
0
0

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 RecordsNavigationController 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 click in the SourceView. This behavior is caused by the fact that RecordsNavigationController lies inside the ListView and 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.

Question Comments

Added By: Bram Essers at: 3/6/2014 1:12:31 AM    

Hi,
Thanks for this clear example. Together with the supplied source code it is easy to follow. I do have a question. I was testing the functionality in the Web Application solution. When I change the selection in the source grid via the check boxes everything works fine. However, when I click on a row in the source grid I get an exception (see below). What can be done to fix this issue?

Regards,
Bram

The error occurred:

     Type: ObjectDisposedException
     Message: Cannot access a disposed object.
Object name: 'DevExpress.ExpressApp.NestedFrame'.
     Data: 0 entries
     Stack trace:

   at DevExpress.ExpressApp.Frame.CheckIsDisposed()
   at DevExpress.ExpressApp.Frame.SetTemplate(IFrameTemplate val)
   at DevExpress.ExpressApp.Editors.DashboardViewItem.BreakLinksToControl(Boolean unwireEventsOnly)
   at DevExpress.ExpressApp.CompositeView.BreakLinksToControls()
   at DevExpress.ExpressApp.View.b__2()
   at DevExpress.Persistent.Base.SafeExecutor.Execute(Method method, Object targetObject, String targetObjectIdentifier)
   at DevExpress.ExpressApp.View.Dispose()
   at DevExpress.ExpressApp.Frame.DisposeView(View view)
   at DevExpress.ExpressApp.Frame.SetView(View view, Boolean updateControllers, Frame sourceFrame)
     InnerException is null

Added By: Alexey (DevExpress Support) at: 3/6/2014 1:39:56 AM    

Hello Bram,
I will answer you in the Q467603 thread

Added By: Marc Greiner (DevExpress MVP) at: 9/22/2016 12:36:37 AM    For a solution that additionally works with ViewVariants, have a look at:
https://www.devexpress.com/Support/Center/Question/Details/T429995

Viewing all articles
Browse latest Browse all 7205

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>