How to: Open a Detail View When the Grid Row is Clicked in the Dashboard
- 8 minutes to read
This topic describes how to invoke a Detail View when a user clicks a row in the GridDashboardItem created using the Dashboards Module. In the invoked Detail View, a user can view or edit a business object corresponding to the clicked row.
WinForms Example
Add a key property to the hidden measures of a Dashboard and set its summary type to Min or Max. The key property in this example is Oid.
- Add a View Controller to the WinForms module project.
- Access the WinDashboardViewerViewItem, as described in the How to: Access the Dashboard Control topic.
- In the ViewItem.ControlCreated event handler, subscribe to the DashboardViewer.DashboardItemControlCreated event.
- In the DashboardItemControlCreated event handler, access the DashboardViewer and subscribe to the DashboardViewer.DashboardItemDoubleClick event.
- In the DashboardItemDoubleClick event handler, get the key property value using the DashboardItemMouseActionEventArgs arguments.
- Add a ParametrizedAction to the Controller and force its execution in the DashboardItemDoubleClick event handler. The Action in the example is invisible because its category (“Dashboard”) does not match any existing Action Container. However, you still can execute it in code using the DoExecute method.
- In the ParametrizedAction.Execute event handler, create a new Object Space and find the clicked object using the IObjectSpace.FindObject method.
- Pass the found object to the XafApplication.CreateDetailView method to create a Detail View.
- Pass the created Detail View to the ShowViewParameters.CreatedView event argument to display it.
ASP.NET Example
Add a key property to the hidden measures of a Dashboard and set its summary type to Min or Max. The key property in this example is Oid.
- Add a View Controller to the ASP.NET module project.
- Access the WebDashboardViewerViewItem, as described in the How to: Access the Dashboard Control topic.
- Add a handler to the client-side ASPxClientDashboard.ItemClick event.
- In this event handler, get the key property value using the ASPxClientDashboardItemClickEventArgs arguments.
- Generate a callback on the client side (in the ASPxClientDashboard item click handler) and process it on the server side (see How to: Raise XAF Callbacks from Client-Side Events and Process these Callbacks on Server).
- Add a ParametrizedAction to the Controller and force its execution in the IXafCallbackHandler.ProcessAction method implementation. The Action in the example is invisible because its category (“Dashboard”) does not match any existing Action Container. However, you still can execute it in code using the DoExecute method.
- In the ParametrizedAction.Execute event handler, create a new Object Space and find the clicked object using the IObjectSpace.FindObject method.
- Pass the found object to the XafApplication.CreateDetailView method to create a Detail View.
- Pass the created Detail View to the ShowViewParameters.CreatedView event argument to display it.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/xaf-win-web-open-detail-view-when-grid-row-is-clicked-in-the-dashboard.
- WinShowDetailViewFromDashboardController.cs
- WebShowDetailViewFromDashboardController.cs
- WebShowDetailViewFromDashboardController.vb
- WinShowDetailViewFromDashboardController.vb
using DevExpress.DashboardCommon;
using DevExpress.DashboardCommon.ViewerData;
using DevExpress.DashboardWin;
using DevExpress.Data.Filtering;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Dashboards.Win;
using DevExpress.Persistent.Base;
using ShowDetailViewFromDashboard.Module.BusinessObjects;
using System;
using System.Linq;
namespace ShowDetailViewFromDashboard.Module.Win.Controllers
{
public class WinShowDetailViewFromDashboardController : ObjectViewController<DetailView, IDashboardData>
{
private ParametrizedAction openDetailViewAction;
protected override void OnActivated()
{
base.OnActivated();
WinDashboardViewerViewItem dashboardViewerViewItem = View.FindItem("DashboardViewer") as WinDashboardViewerViewItem;
if (dashboardViewerViewItem != null)
{
if (dashboardViewerViewItem.Viewer != null)
{
dashboardViewerViewItem.Viewer.DashboardItemDoubleClick += Viewer_DashboardItemDoubleClick;
}
dashboardViewerViewItem.ControlCreated += DashboardViewerViewItem_ControlCreated;
}
}
private void DashboardViewerViewItem_ControlCreated(object sender, EventArgs e)
{
WinDashboardViewerViewItem dashboardViewerViewItem = sender as WinDashboardViewerViewItem;
dashboardViewerViewItem.Viewer.DashboardItemDoubleClick += Viewer_DashboardItemDoubleClick;
}
private bool IsGridDashboardItem(Dashboard dashboard, string dashboardItemName)
{
DashboardItem dashboardItem = dashboard.Items.SingleOrDefault(item => item.ComponentName == dashboardItemName);
return dashboardItem is GridDashboardItem;
}
private static string GetOid(DashboardItemMouseActionEventArgs e)
{
MultiDimensionalData data = e.Data.GetSlice(e.GetAxisPoint());
MeasureDescriptor descriptor = data.GetMeasures().SingleOrDefault(item => item.DataMember == "Oid");
MeasureValue measureValue = data.GetValue(descriptor);
return measureValue.Value.ToString();
}
private void Viewer_DashboardItemDoubleClick(object sender, DashboardItemMouseActionEventArgs e)
{
Dashboard dashboard = ((DashboardViewer)sender).Dashboard;
if (IsGridDashboardItem(dashboard, e.DashboardItemName) &&
openDetailViewAction.Enabled && openDetailViewAction.Active)
{
openDetailViewAction.DoExecute(GetOid(e));
}
}
private void OpenDetailViewAction_Execute(object sender, ParametrizedActionExecuteEventArgs e)
{
IObjectSpace objectSpace = Application.CreateObjectSpace(typeof(Contact));
Contact contact = objectSpace.FindObject<Contact>(new BinaryOperator("Oid", e.ParameterCurrentValue.ToString()));
if (contact != null)
{
e.ShowViewParameters.CreatedView = Application.CreateDetailView(objectSpace, contact, View);
}
}
protected override void OnDeactivated()
{
WinDashboardViewerViewItem dashboardViewerViewItem = View.FindItem("DashboardViewer") as WinDashboardViewerViewItem;
if (dashboardViewerViewItem != null)
{
dashboardViewerViewItem.ControlCreated -= DashboardViewerViewItem_ControlCreated;
}
base.OnDeactivated();
}
public WinShowDetailViewFromDashboardController()
{
openDetailViewAction = new ParametrizedAction(this, "Dashboard_OpenDetailView", "Dashboard", typeof(string));
openDetailViewAction.Caption = "OpenDetailView";
openDetailViewAction.SelectionDependencyType = SelectionDependencyType.RequireSingleObject;
openDetailViewAction.Execute += OpenDetailViewAction_Execute;
}
}
}