DataGridColumn.SortMemberPath Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets a property name, or a period-delimited hierarchy of property names, that indicates the member to sort by.

Namespace:  System.Windows.Controls
Assembly:  System.Windows.Controls.Data (in System.Windows.Controls.Data.dll)

Syntax

'Declaration
Public Property SortMemberPath As String
public string SortMemberPath { get; set; }
<sdk:dataGridColumn SortMemberPath="path"/>

XAML Values

Property Value

Type: System.String
The path to the data-item member to sort by.

Remarks

In columns that are derived from DataGridBoundColumn, such as DataGridTextColumn and DataGridCheckBoxColumn, the SortMemberPath is set to the property that the column is bound to through the Binding property by default. In columns that are derived from DataGridColumn, such as DataGridTemplateColumn, the SortMemberPath property must be set to enable automatic sorting of the column.

Examples

The following code example demonstrates how to set the SortMemberPath property. This example is part of a larger example available in the How to: Customize Auto-Generated Columns in the DataGrid Control topic.

' Create a new template column.
Dim templateColumn As New DataGridTemplateColumn
templateColumn.Header = "Due Date"
templateColumn.CellTemplate = Me.Resources("dueDateCellTemplate")
templateColumn.CellEditingTemplate = Me.Resources("dueDateCellEditingTemplate")
templateColumn.SortMemberPath = "DueDate"
// Create a new template column.
DataGridTemplateColumn templateColumn = new DataGridTemplateColumn();
templateColumn.Header = "Due Date";
templateColumn.CellTemplate = (DataTemplate)Resources["dueDateCellTemplate"];
templateColumn.CellEditingTemplate = (DataTemplate)Resources["dueDateCellEditingTemplate"];
templateColumn.SortMemberPath = "DueDate";

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.