How To: Pass Specific Data when Navigating Through Containers

  • 5 minutes to read

The start-up application screen contains a Page container (page1) with a GridControl. Double-clicking a grid row takes a user to page2, which contains a separate Grid with detailed employee information. Both containers' documents contain user controls (ucGeneral and ucDetails, respectively).

  1. In the Designer's "Navigation Tree" tab, drag Page2 to the Page1 "Children" line. By doing so you assign Page1 to the Page2's BaseContentContainer.Parent property and make it possible for end-users to navigate back from the detailed employee information page.

    WindowsUIVIew - Tree 4

  2. Handle the WindowsUIView.NavigatedTo event, and assign the details Page to the NavigationEventArgs.Parameter property.

    
    private void windowsUIView1_NavigatedTo(object sender, DevExpress.XtraBars.Docking2010.Views.WindowsUI.NavigationEventArgs e) {
        if (e.Target == page1) e.Parameter = page2;
    }
    
  3. Implement the ISupportNavigation interface and expose its ISupportNavigation.OnNavigatedTo and ISupportNavigation.OnNavigatedFrom methods for both UserControls. At application start-up, the OnNavigatedTo method for the ucGeneral UserControl receives the details page as a parameter from the NavigatedTo event that was handled in the previous step.

    
    //ucGeneral.cs
    public partial class ucGeneral : UserControl, ISupportNavigation {
        WindowsUIView generalView;
        Page detailsPage;
    
        public void OnNavigatedFrom(INavigationArgs args) {
    
        }
    
        public void OnNavigatedTo(INavigationArgs args) {
            generalView = args.View;
            detailsPage = args.Parameter as Page;
        }
    }
    
  4. Set the ColumnViewOptionsBehavior.Editable property to false, so that you can handle the double-click event. This property is located in the GridView.OptionsBehavior section.
  5. Handle the GridView's double click event and call the IBaseViewController.Activate method to navigate to the details page.

    
    //ucGeneral.cs
    private void gridView1_DoubleClick(object sender, EventArgs e) {
        generalView.Controller.Activate(detailsPage);
    }
    
  6. Handle the OnNavigatedFrom method for the general page and assign the focused row to the Parameter property. This parameter is passed to the OnNavigatedTo method of the details page, and you are able to retrieve any required data and fill the details page. In this example, a simple filter criteria is applied.

    
    //ucGeneral.cs
    public void OnNavigatedFrom(INavigationArgs args) {
        args.Parameter = gridView1.GetDataRow(gridView1.FocusedRowHandle);
    }
    
    //ucDetails.cs
    public void OnNavigatedTo(INavigationArgs args) {
        detailsID = (args.Parameter as ParamNavigation.nwindDataSet.EmployeesRow).EmployeeID.ToString();
        layoutView1.ActiveFilterString = "[EmployeeID] = " + detailsID;
    }
    
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraBars.Docking2010.Views.WindowsUI;

namespace ParamNavigation {
    public partial class ucGeneral : UserControl, ISupportNavigation {
        WindowsUIView generalView;
        Page detailsPage;
        public ucGeneral() {
            InitializeComponent();
            employeesTableAdapter.Fill(nwindDataSet.Employees);
        }

        public void OnNavigatedFrom(INavigationArgs args) {
            args.Parameter = gridView1.GetDataRow(gridView1.FocusedRowHandle);
        }

        public void OnNavigatedTo(INavigationArgs args) {
            generalView = args.View;
            detailsPage = args.Parameter as Page;
        }

        private void gridView1_DoubleClick(object sender, EventArgs e) {
            generalView.Controller.Activate(detailsPage);
        }
    }
}