Back to Devexpress

How To: Pass Specific Data when Navigating Through Containers

windowsforms-14907-controls-and-libraries-application-ui-manager-views-windowsui-view-getting-started-how-to-pass-specific-data-when-navigating-through-containers.md

latest9.3 KB
Original Source

How To: Pass Specific Data when Navigating Through Containers

  • Nov 13, 2018
  • 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.

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

  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.

  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.

  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.

csharp
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);
        }
    }
}
csharp
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ParamNavigation {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        private void windowsUIView1_NavigatedTo(object sender, DevExpress.XtraBars.Docking2010.Views.WindowsUI.NavigationEventArgs e) {
            if (e.Target == page1) e.Parameter = page2;
        }

        private void windowsUIView1_QueryControl(object sender, DevExpress.XtraBars.Docking2010.Views.QueryControlEventArgs e) {
            if (e.Document == document1) e.Control = new ucGeneral();
            else e.Control = new ucDetails();
        }
    }
}
csharp
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 ucDetails : UserControl, ISupportNavigation {
        string detailsID;
        public ucDetails() {
            InitializeComponent();
            employeesTableAdapter.Fill(nwindDataSet.Employees);
        }

        public void OnNavigatedFrom(INavigationArgs args) {

        }

        public void OnNavigatedTo(INavigationArgs args) {
            detailsID = (args.Parameter as ParamNavigation.nwindDataSet.EmployeesRow).EmployeeID.ToString();
            layoutView1.ActiveFilterString = "[EmployeeID] = " + detailsID;
        }
    }
}
vb
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing
Imports System.Data
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows.Forms
Imports DevExpress.XtraBars.Docking2010.Views.WindowsUI

Namespace ParamNavigation
    Public Partial Class ucGeneral
        Inherits UserControl
        Implements ISupportNavigation
        Private generalView As WindowsUIView
        Private detailsPage As Page
        Public Sub New()
            InitializeComponent()
            employeesTableAdapter.Fill(nwindDataSet.Employees)
        End Sub

        Public Sub OnNavigatedFrom(ByVal args As INavigationArgs) Implements ISupportNavigation.OnNavigatedFrom
            args.Parameter = gridView1.GetDataRow(gridView1.FocusedRowHandle)
        End Sub

        Public Sub OnNavigatedTo(ByVal args As INavigationArgs) Implements ISupportNavigation.OnNavigatedTo
            generalView = args.View
            detailsPage = TryCast(args.Parameter, Page)
        End Sub

        Private Sub gridView1_DoubleClick(ByVal sender As Object, ByVal e As EventArgs) Handles gridView1.DoubleClick
            generalView.Controller.Activate(detailsPage)
        End Sub
    End Class
End Namespace
vb
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows.Forms

Namespace ParamNavigation
    Public Partial Class Form1
        Inherits Form
        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub windowsUIView1_NavigatedTo(ByVal sender As Object, ByVal e As DevExpress.XtraBars.Docking2010.Views.WindowsUI.NavigationEventArgs) Handles windowsUIView1.NavigatedTo
            If e.Target Is page1 Then
            e.Parameter = page2
            End If
        End Sub

        Private Sub windowsUIView1_QueryControl(ByVal sender As Object, ByVal e As DevExpress.XtraBars.Docking2010.Views.QueryControlEventArgs) Handles windowsUIView1.QueryControl
            If e.Document Is document1 Then
            e.Control = New ucGeneral()
            Else
                e.Control = New ucDetails()
            End If
        End Sub
    End Class
End Namespace
vb
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing
Imports System.Data
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows.Forms
Imports DevExpress.XtraBars.Docking2010.Views.WindowsUI

Namespace ParamNavigation
    Public Partial Class ucDetails
        Inherits UserControl
        Implements ISupportNavigation
        Private detailsID As String
        Public Sub New()
            InitializeComponent()
            employeesTableAdapter.Fill(nwindDataSet.Employees)
        End Sub

        Public Sub OnNavigatedFrom(ByVal args As INavigationArgs) Implements ISupportNavigation.OnNavigatedFrom

        End Sub

        Public Sub OnNavigatedTo(ByVal args As INavigationArgs) Implements ISupportNavigation.OnNavigatedTo
            detailsID = (TryCast(args.Parameter, ParamNavigation.nwindDataSet.EmployeesRow)).EmployeeID.ToString()
            layoutView1.ActiveFilterString = "[EmployeeID] = " & detailsID
        End Sub
    End Class
End Namespace