How to: Move an Existing Dashboard Item to Another Group
- 3 minutes to read
Important
This documentation applies to v16.2. Starting with v17.1, the ASPxDashboardViewer control is in maintenance mode. In v19.1, the new Web Dashboard Control replaces the old Web Dashboard Viewer. This means that the Web Dashboard Viewer will not be included in our installation packages. See our blog post for more information.
Refer to the following KB articles to learn how to migrate to ASPxDashboard / ASP.NET MVC Dashboard:
ASPxDashboardViewer -> ASPxDashboard
How to migrate from ASPxDashboardViewer to ASPxDashboard working in the ViewerOnly mode
MVCxDashboardViewer -> MVCxDashboard
How to migrate from DashboardViewerExtension to DashboardExtension working in the ViewerOnly mode
The following example demonstrates how to move an existing dashboard item from the dashboard item group to another group in code.
In this example, the ASPxDashboardViewer loads an existing dashboard with the predefined layout from an XML file.
The following steps are performed to move the combo box placed in the bottom group into the top group.
- The required layout items and the dashboard layout group are obtained using the DashboardLayoutGroup.FindRecursive method.
- The DashboardLayoutNode.MoveAbove method is used to move a combo box layout item above the tree view placed in the top group.
- The DashboardItem.Group property specifies a new parent group for the combo box.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-move-an-existing-dashboard-item-to-another-group-t207077.
using System;
using DevExpress.DashboardWeb;
using DevExpress.DataAccess.ConnectionParameters;
using DevExpress.DashboardCommon;
namespace Dashboard_MoveItemFromGroupToGroup {
public partial class WebForm1 : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
}
protected void ASPxDashboardViewer1_DashboardLoaded(object sender,
DashboardLoadedWebEventArgs e) {
Dashboard dashboard = e.Dashboard;
ComboBoxDashboardItem comboBox =
(ComboBoxDashboardItem)dashboard.Items["comboBoxDashboardItem1"];
TreeViewDashboardItem treeView =
(TreeViewDashboardItem)dashboard.Items["treeViewDashboardItem1"];
DashboardItemGroup topGroup =
(DashboardItemGroup)dashboard.Groups["dashboardItemGroup1"];
DashboardLayoutGroup root = e.Dashboard.LayoutRoot;;
DashboardLayoutItem comboBoxLayoutItem = root.FindRecursive(comboBox);
DashboardLayoutItem treeViewLayoutItem = root.FindRecursive(treeView);
DashboardLayoutGroup topGroupItem = root.FindRecursive(topGroup);
comboBoxLayoutItem.MoveAbove(treeViewLayoutItem);
comboBox.Group = topGroup;
}
protected void ASPxDashboardViewer1_ConfigureDataConnection(object sender,
ConfigureDataConnectionWebEventArgs e) {
if (e.ConnectionName == "WebsiteStatisticsDataConnection") {
XmlFileConnectionParameters parameters =
(XmlFileConnectionParameters)e.ConnectionParameters;
string databasePath = Server.MapPath("App_Data/WebsiteStatisticsData.xml");
parameters.FileName = databasePath;
}
}
}
}