Open a Detail View When the Grid Row is Clicked in the Dashboard (WinForms)
- 2 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.
Add a key property to the hidden measures of a Dashboard and set its summary type to
MinorMax. The key property in this example isOid.
Add a View Controller to the WinForms application project (MySolution.Win).
- Access the WinDashboardViewerViewItem according to the How to: Access the Dashboard Control topic.
- Access the DashboardViewer and subscribe to the DashboardViewer.DashboardItemDoubleClick event.
- In the
DashboardItemDoubleClickevent handler, get the key property value using the DashboardItemMouseActionEventArgs arguments. - Create a new Object Space and use the IObjectSpace.FirstOrDefault method to find the clicked object.
- Pass the found object to the XafApplication.CreateDetailView method to create a Detail View.
- Pass the created Detail View to the ShowViewFromCommonView(View, Frame, ActionBase) method to display it.
using DevExpress.DashboardCommon;
using DevExpress.DashboardCommon.ViewerData;
using DevExpress.DashboardWin;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Dashboards.Win;
using DevExpress.Persistent.Base;
using OpenViewFromDashboardEF.Module.BusinessObjects;
public class WinShowDetailViewFromDashboardController :ObjectViewController<DetailView, IDashboardData> {
protected override void OnActivated() {
base.OnActivated();
View.CustomizeViewItemControl<WinDashboardViewerViewItem>(this, item => {
item.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 Guid GetID(DashboardItemMouseActionEventArgs e) {
MultiDimensionalData data = e.Data.GetSlice(e.GetAxisPoint());
MeasureDescriptor descriptor = data.GetMeasures().SingleOrDefault(item => item.DataMember == "ID");
MeasureValue measureValue = data.GetValue(descriptor);
return (Guid)measureValue.Value;
}
private void Viewer_DashboardItemDoubleClick(object sender, DashboardItemMouseActionEventArgs e) {
Dashboard dashboard = ((DashboardViewer)sender).Dashboard;
if(IsGridDashboardItem(dashboard, e.DashboardItemName)) {
OpenDetailView(GetID(e));
}
}
private void OpenDetailView(Guid contactId) {
IObjectSpace objectSpace = Application.CreateObjectSpace<Contact>();
Contact contact = objectSpace.FirstOrDefault<Contact>(c => c.ID == contactId);
if(contact != null) {
DetailView detailView = Application.CreateDetailView(objectSpace, contact, View);
Application.ShowViewStrategy.ShowViewFromCommonView(detailView);
}
}
}