DataBinding a WPF DataGrid
Binding a WPF DataGrid
To data bind a WPF ListView, you should set the DataContext property of the DataGrid or one of its parent containers (such as the Window its contained in) as described in Data Binding WPF Controls. Afterwards, you set its ItemSource property to the desired DataContext.
For example, to bind a DataGrid to a Window-level Data Context that is set to an OrderEntity object, follow these steps:
- In Visual Studio, select the DataGrid in the design surface (or in the Document Outline window). Go to the Properties panel under the Columns section and click the tiny Advanced property options button to the right of the ItemsSource property, and select Create Data Binding... from the shortcut menu.

- In the Create Data Binding dialog, the Binding Type should be set to Data Context, with the OrderEntity object shown in the Path box on the right side of the dialog:

- Click OK to bind the DataGrid to the explicit data context of the window. When you're done, the ItemsSource property will have an amber ellipse displayed around it, indicating the ItemsSource property is data bound:

To set up the individual columns in the DataGrid, see the section below, Binding DataGrid Columns.
Retrieving Entities to Fill a DataGrid
Now that you have set up the data binding for the DataGrid, you need to instantiate a business object in the window's code-behind file and retrieve an entity list to fill the list.For example, in C#:
public partial class OrdersWindow : mmBusinessWindow
{
Order Order;
/// <summary>
/// Constructor
/// </summary>
public OrdersWindow()
{
this.Order = (Order)this.RegisterPrimaryBizObj(new Order());
this.InitializeComponent();
this.DataContext = this.Order.GetAllEntities();
}
}And in VB .NET:
Public Partial Class OrdersWindow
Inherits mmBusinessWindow
Dim Order As Order
''' <summary>
''' Constructor
''' </summary>
Public Sub New()
Me.Order = CType(Me.RegisterPrimaryBizObj(New Order()), Order)
Me.InitializeComponent()
Me.DataContext = Me.Order.GetAllEntities()
End Sub
End ClassNow when you run your WPF window, the list should display the entities returned from your business object.
Binding DataGrid Columns
For a step-by-step, detailed explanation of binding a DataGrid's columns, see the Jump Start: WPF Application - C# topic's Step 12: Enhancing the DataGrids.Follow the instructions in this topic to use a Data Grid on an MM .NET WPF Business Form.
Setting a DataGrid as a Window's Navigation Control
- Specify the DataContext on the Data Grid or one of its parent containers
- In the Window's constructor specify the Data Grid as the Window's NavigationControl.
For example, in C#:
this.NavigationControl = this.grdEmployees;
And in VB .NET:
Me.NavigationControl = Me.grdEmployees
© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 04/26/18
Comment or report problem with topic
