Data​Grid Class

Definition

Represents a control that displays data in a customizable grid.

public class DataGrid : System.Windows.Controls.Primitives.MultiSelector
Inheritance

Inherited Members

System.Object

System.Windows.Controls.Control

System.Windows.Controls.ItemsControl

System.Windows.Controls.Primitives.MultiSelector

System.Windows.Controls.Primitives.Selector

System.Windows.DependencyObject

System.Windows.FrameworkElement

System.Windows.Media.Visual

System.Windows.Threading.DispatcherObject

System.Windows.UIElement

Examples

The following example shows how to bind a DataGrid to a DataTable and use column auto-generation. The DataTable is populated by using the Fill method of a DataAdapter from a DataSet. For more information, see Creating a DataSet and Populating a DataSet from a DataAdapter. To use the WPF Designer for Visual Studio, see Bind WPF controls to data in Visual Studio.

<DataGrid x:Name="CustomerGrid" ItemsSource="{Binding}" AlternatingRowBackground="LightBlue" AlternationCount="2" />
//Set the DataGrid's DataContext to be a filled DataTable
CustomerGrid.DataContext = custDataTable;
'Set the DataGrid's DataContext to be a filled DataTable
CustomerGrid.DataContext = custDataTable

The following example shows how to create a DataGrid with a customized Columns collection.

    <NavigationWindow x:Class="DataGrid_CustomColumns.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:core="clr-namespace:System;assembly=mscorlib"
        xmlns:local="clr-namespace:DataGrid_CustomColumns"
        Title="Customers" Height="300" Width="300" ShowsNavigationUI="False"  >
        
    <NavigationWindow.Resources>
        <!--Create list of enumeration values-->
        <ObjectDataProvider x:Key="myEnum" MethodName="GetValues" ObjectType="{x:Type core:Enum}">
            <ObjectDataProvider.MethodParameters>
                <x:Type Type="local:OrderStatus"/>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
        <!--Create an instance of the converter for Email-->
        <local:EmailConverter x:Key="EmailConverter" />
    </NavigationWindow.Resources>
    <NavigationWindow.Content>  
        
    <Grid>
        <DataGrid Name="DG1" ItemsSource="{Binding}" AutoGenerateColumns="False" >
            <DataGrid.Columns>
                <DataGridTextColumn Header="First Name"  Binding="{Binding FirstName}"/>
                <DataGridTextColumn Header="Last Name" Binding="{Binding LastName}" />
                <!--The Email property contains a URI.  For example "mailto:lucy0@adventure-works.com"-->
                <DataGridHyperlinkColumn Header="Email" Binding="{Binding Email}"  ContentBinding="{Binding Email, Converter={StaticResource EmailConverter}}" />
                <DataGridCheckBoxColumn Header="Member?" Binding="{Binding IsMember}" />
                <DataGridComboBoxColumn Header="Order Status"  SelectedItemBinding="{Binding Status}" ItemsSource="{Binding Source={StaticResource myEnum}}" />
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
    </NavigationWindow.Content>
</NavigationWindow>
//Additional using statements
using System.Data;
using System.Collections.ObjectModel;
using System.Diagnostics;
'Additional using statements
Imports System.Data
Imports System.Collections.ObjectModel
Imports System.Diagnostics
public partial class Window1 : NavigationWindow
{
Class Window1
public Window1()
{
    InitializeComponent();

    //GetData() creates a collection of Customer data from a database
    ObservableCollection<Customer> custdata = GetData();
    
    //Bind the DataGrid to the customer data
    DG1.DataContext = custdata;
   
}
Public Sub New()
    ' This call is required by the Windows Form Designer.
    InitializeComponent()
    ' Add any initialization after the InitializeComponent() call.

    'GetData() creates a collection of Customer data from a database
    Dim custdata As ObservableCollection(Of Customer) = GetData()

    'Bind the DataGrid to the customer data
    DG1.DataContext = custdata

End Sub
//Defines the customer object
public class Customer
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public Uri Email { get; set; }
    public bool IsMember { get; set; }
    public OrderStatus Status { get; set; }

}
'Defines the customer object
Public Class Customer
    Public Property FirstName() As String
    Public Property LastName() As String
    Public Property Email() As Uri
    Public Property IsMember() As Boolean
    Public Property Status() As OrderStatus
End Class
}
End Class
public enum OrderStatus { None, New, Processing, Shipped, Received };
Public Enum OrderStatus
    None
    [New]
    Processing
    Shipped
    Received
End Enum
//Converts the mailto uri to a string with just the customer alias
public class EmailConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (value != null)
        {
            string email = value.ToString();
            int index = email.IndexOf("@");
            string alias = email.Substring(7, index-7);
            return alias;
        }
        else
        {
            string email = "";
            return email;
        }
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        Uri email = new Uri((string)value);
        return email;
    }
}
'Converts the mailto uri to a string with just the customer alias
Public Class EmailConverter
    Implements IValueConverter

    Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
        If value IsNot Nothing Then
            Dim email As String = value.ToString()
            Dim index As Integer = email.IndexOf("@")
            Dim [alias] As String = email.Substring(7, index - 7)
            Return [alias]
        Else
            Dim email As String = ""
            Return email
        End If
    End Function

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
        Dim email As New Uri(DirectCast(value, String))
        Return email
    End Function
End Class

Remarks

The DataGrid control provides a flexible way to display a collection of data in rows and columns. The DataGrid includes built-in column types and a template column for hosting custom content. The built-in row type includes a drop-down details section that you can use to display additional content below the cell values.

Binding to Data

To bind the DataGrid to data, set the ItemsSource property to an IEnumerable implementation. Each row in the data grid is bound to an object in the data source, and each column in the data grid is bound to a property of the data object. In order for the DataGrid user interface to update automatically when items are added to or removed from the source data, the DataGrid must be bound to a collection that implements the INotifyCollectionChanged interface, such as an ObservableCollection<T>. To automatically reflect property changes, the objects in the source collection must implement the INotifyPropertyChanged interface. For more information, see Data Binding (WPF).

Columns

By default, the DataGrid control generates columns automatically when you set the ItemsSource property. The type of column that is generated depends on the type of data in the column. The following table lists the generated columns types.

Generated Column Type Data Type
DataGridTextColumn String
DataGridCheckBoxColumn Boolean
DataGridComboBoxColumn Enum
DataGridHyperlinkColumn Uri

The following illustration shows each of the column types.

DataGrid with all four default column types

When columns are auto-generated, you can handle the AutoGeneratingColumn event to customize or cancel columns before they are added to the DataGrid. If you add both user-defined columns and auto-generated columns to the DataGrid, the user-defined columns are added first. To rearrange the display order of the columns, you can set the DisplayIndex property for individual columns.

You can prevent automatic column generation by setting the AutoGenerateColumns property to false. This is useful if you want to create and configure all columns explicitly.

Use the DataGridTemplateColumn type to define a custom column if the built-in column types do not meet your needs. The DataGridTemplateColumn type provides CellTemplate and CellEditingTemplate properties that enable you to specify content templates for both display and editing modes. For example, you could define a custom column for dates. The CellTemplate could define a TextBlock to display a date, and the CellEditingTemplate could define a DatePicker control to edit the date.

You can use the Columns collection to programmatically add, insert, remove, and change any columns in the control at run time. Check the IsAutoGenerated property to determine whether a column is auto generated or user defined. Auto-generated columns will be automatically added, removed, or regenerated when the ItemsSource changes.

Selection

By default, the entire row is selected when a user clicks a cell in a DataGrid, and a user can select multiple rows. You can set the SelectionMode property to specify whether a user can select cells, full rows, or both. Set the SelectionUnit property to specify whether multiple rows or cells can be selected, or only single rows or cells.

You can get information about the cells that are selected from the SelectedCells property. You can get information about cells for which selection has changed in the SelectedCellsChangedEventArgs of the SelectedCellsChanged event. Call the SelectAllCells or UnselectAllCells methods to programmatically select or unselect all cells. For more information, see Default Keyboard and Mouse Behavior in the DataGrid Control.

Grouping, Sorting, and Filtering

By default, you can sort items in a DataGrid by clicking the column header. You can customize sorting by handling the Sorting event. To cancel the default sort, set the Handled property to true. You can also sort the source data before it is displayed in the DataGrid.

To group, sort, and filter data in the DataGrid, you bind the DataGrid to an ICollectionView implementation that supports these operations. You then perform the operations on the collection view. When items are grouped in the DataGrid, you can define a GroupStyle that specifies the appearance of each group. You apply the GroupStyle by adding it to the GroupStyle collection of the DataGrid. If you have multiple levels of grouping, you can apply different styles to each group level. Styles are applied in the order in which they are defined. For more information, see How to: Group, Sort, and Filter Data in the DataGrid Control.

Editing

By default, you can edit items directly in the DataGrid. To guarantee that edits can be committed and canceled correctly, the objects in the DataGrid must implement the IEditableObject interface. Alternatively, you can set the IsReadOnly property to true to disable editing in the DataGrid.

The DataGrid has built-in support for the following editing commands:

Command Default Input Binding
BeginEditCommand F2
CancelEditCommand ESC
CommitEditCommand ENTER
DeleteCommand DELETE

You put the current cell into edit mode by clicking it or pressing F2. A cell-level edit is committed when you move to another cell in the same row or press ENTER while the cell is in edit mode. All edits in a row are committed when you move to another row or press ENTER while the row is in edit mode. You cancel a cell edit by pressing ESC one time, and cancel all edits in a row by pressing ESC two times. For more information about programmatically committing and canceling edits, see the BeginEdit, CommitEdit, and CancelEdit methods. For more information about edit-related events, see BeginningEdit, PreparingCellForEdit, CellEditEnding, and RowEditEnding.

Set the CanUserAddRows and CanUserDeleteRows properties to specify whether a user can add or delete rows. A user can delete selected rows by pressing the DELETE key. If the CanUserAddRows property is set to true, a new item row is added as the last row in the DataGrid. You can set default values for new items by handling the InitializingNewItem event.

Note

Whether editing actions are allowed is influenced by a variety of additional factors, including the IsReadOnly and IsEnabled state of the DataGrid, and whether the underlying data collection allows the action.

Validation

The DataGrid enables you to perform validation at both the cell and row level. With cell-level validation, you validate individual properties of a bound data object when a user updates a value. With row-level validation, you validate entire data objects when a user commits changes to a row. You can provide customized visual feedback for row-level validation errors by setting the RowValidationErrorTemplate property, or you can use the default error indicator. To create a custom validation rule, create a class that derives from the ValidationRule class and implement the Validate method. Add the custom validation rule to the RowValidationRules collection.

Customizing the DataGrid Control

The DataGrid control supports common table formatting options, such as alternating row backgrounds and the ability to show or hide headers, gridlines, and scroll bars. Additionally, the control provides several style and template properties that you can use to completely change the appearance of the control and its rows, columns, headers, and cells.

To customize DataGrid behavior, you can handle events for selection change, cell editing, and column re-ordering. The DataGrid also exposes several events for row recycling that you can handle to customize rows.

To apply the same property settings to multiple DataGrid controls, use the Style property. You can modify the default ControlTemplate to give the control a unique appearance. For more information about creating a ControlTemplate, see Customizing the Appearance of an Existing Control by Creating a ControlTemplate. To see the parts and states that are specific to the DataGrid, see DataGrid Styles and Templates.

Dependency properties for this control might be set by the control’s default style. If a property is set by a default style, the property might change from its default value when the control appears in the application. The default style is determined by which desktop theme is used when the application is running. For more information, see Default WPF Themes.

Note

Setting a visual property will only have an effect if that property is both present in the DataGrid control's default template and is set by using a . You can find a list of visual properties in the "Changing the Visual Structure of a Control" section in Customizing the Appearance of an Existing Control by Creating a ControlTemplate.

Common Tasks

The following table provides information about tasks that are typically associated with the DataGrid.

Task Implementation
Set alternating row background colors Set the AlternationIndex property to 2 or more, and then assign a Brush to the RowBackground and AlternatingRowBackground properties.
Define cell and row selection behavior Set the SelectionMode and SelectionUnit properties.
Customize the visual appearance of headers, cells and rows Apply a new Style to the ColumnHeaderStyle, RowHeaderStyle, CellStyle, or RowStyle properties.
Set sizing options Set the Height, MaxHeight, MinHeight, Width, MaxWidth, or MinWidth properties. For more information, see Sizing Options in the DataGrid Control.
Access selected items Check the SelectedCells property to get the selected cells and check the SelectedItems property to get the selected rows. For more information, see the SelectedCells property.
Customize end-user interactions Set the CanUserAddRows, CanUserDeleteRows, CanUserReorderColumns, CanUserResizeColumns, CanUserResizeRows, and CanUserSortColumns properties.
Cancel or change auto-generated columns Handle the AutoGeneratingColumn event.
Freeze a column Set the FrozenColumnCount property to 1 and move the column to the left-most position by setting the DisplayIndex property to 0.
Use XML data as the data source Bind the ItemsSource on the DataGrid to the XPath query representing the collection of items. Create each column in the DataGrid. Bind each column by setting the XPath on the binding to the query that gets the property on the item source. For an example, see DataGridTextColumn.
Group items Bind to a CollectionView or CollectionViewSource that supports grouping. For more information, see How to: Group, Sort, and Filter Data in the DataGrid Control.
Display the details section for a row Define a RowDetailsTemplate to specify the appearance of the details section. Set the RowDetailsVisibilityMode to specify when the details section is shown. For more information, see How to: Add Row Details to a DataGrid Control.

Constructors

Data​Grid()

Initializes a new instance of the DataGrid class.

Fields

Alternating​Row​Background​Property

Identifies the AlternatingRowBackground dependency property.

Are​Row​Details​Frozen​Property

Identifies the AreRowDetailsFrozen dependency property.

Auto​Generate​Columns​Property

Identifies the AutoGenerateColumns dependency property.

Begin​Edit​Command

Represents the command that indicates the intention to begin editing the current cell or row of the DataGrid.

Cancel​Edit​Command

Represents the command that indicates the intention to cancel any pending changes to the current cell or row and revert to the state before the BeginEditCommand command was executed.

Can​User​Add​Rows​Property

Identifies the CanUserAddRows dependency property.

Can​User​Delete​Rows​Property

Identifies the CanUserDeleteRows dependency property.

Can​User​Reorder​Columns​Property

Identifies the CanUserReorderColumns dependency property.

Can​User​Resize​Columns​Property

Identifies the CanUserResizeColumns dependency property.

Can​User​Resize​Rows​Property

Identifies the CanUserResizeRows dependency property.

Can​User​Sort​Columns​Property

Identifies the CanUserSortColumns dependency property.

Cells​Panel​Horizontal​Offset​Property

Identifies the CellsPanelHorizontalOffset dependency property.

Cell​Style​Property

Identifies the CellStyle dependency property.

Clipboard​Copy​Mode​Property

Identifies the ClipboardCopyMode dependency property.

Column​Header​Height​Property

Identifies the ColumnHeaderHeight dependency property.

Column​Header​Style​Property

Identifies the ColumnHeaderStyle dependency property.

Column​Width​Property

Identifies the ColumnWidth dependency property.

Commit​Edit​Command

Represents the command that indicates the intention to commit pending changes to the current cell or row and exit edit mode.

Current​Cell​Property

Identifies the CurrentCell dependency property.

Current​Column​Property

Identifies the CurrentColumn dependency property.

Current​Item​Property

Identifies the CurrentItem dependency property.

Drag​Indicator​Style​Property

Identifies the DragIndicatorStyle dependency property.

Drop​Location​Indicator​Style​Property

Identifies the DropLocationIndicatorStyle dependency property.

Enable​Column​Virtualization​Property

Identifies the EnableColumnVirtualization dependency property.

Enable​Row​Virtualization​Property

Identifies the EnableRowVirtualization dependency property.

Frozen​Column​Count​Property

Identifies the FrozenColumnCount dependency property.

Grid​Lines​Visibility​Property

Identifies the GridLinesVisibility dependency property.

Headers​Visibility​Property

Identifies the HeadersVisibility dependency property.

Horizontal​Grid​Lines​Brush​Property

Identifies the HorizontalGridLinesBrush dependency property.

Horizontal​Scroll​Bar​Visibility​Property

Identifies the HorizontalScrollBarVisibility dependency property.

Is​Read​Only​Property

Identifies the IsReadOnly dependency property.

Max​Column​Width​Property

Identifies the MaxColumnWidth dependency property.

Min​Column​Width​Property

Identifies the MinColumnWidth dependency property.

Min​Row​Height​Property

Identifies the MinRowHeight dependency property.

New​Item​Margin​Property

Identifies the NewItemMargin dependency property.

Non​Frozen​Columns​Viewport​Horizontal​Offset​Property

Identifies the NonFrozenColumnsViewportHorizontalOffset dependency property.

Row​Background​Property

Identifies the RowBackground dependency property.

Row​Details​Template​Property

Identifies the RowDetailsTemplate dependency property.

Row​Details​Template​Selector​Property

Identifies the RowDetailsTemplateSelector dependency property.

Row​Details​Visibility​Mode​Property

Identifies the RowDetailsVisibilityMode dependency property.

Row​Header​Actual​Width​Property

Identifies the RowHeaderActualWidth dependency property.

Row​Header​Style​Property

Identifies the RowHeaderStyle dependency property.

Row​Header​Template​Property

Identifies the RowHeaderTemplate dependency property.

Row​Header​Template​Selector​Property

Identifies the RowHeaderTemplateSelector dependency property.

Row​Header​Width​Property

Identifies the RowHeaderWidth dependency property.

Row​Height​Property

Identifies the RowHeight dependency property.

Row​Style​Property

Identifies the RowStyle dependency property.

Row​Style​Selector​Property

Identifies the RowStyleSelector dependency property.

Row​Validation​Error​Template​Property

Identifies the RowValidationErrorTemplate dependency property.

Selection​Mode​Property

Identifies the SelectionMode dependency property.

Selection​Unit​Property

Identifies the SelectionUnit dependency property.

Vertical​Grid​Lines​Brush​Property

Identifies the VerticalGridLinesBrush dependency property.

Vertical​Scroll​Bar​Visibility​Property

Identifies the VerticalScrollBarVisibility dependency property.

Properties

Alternating​Row​Background

Gets or sets the background brush for use on alternating rows.

Are​Row​Details​Frozen

Gets or sets a value that indicates whether the row details can scroll horizontally.

Auto​Generate​Columns

Gets or sets a value that indicates whether the columns are created automatically.

Can​User​Add​Rows

Gets or sets a value that indicates whether the user can add new rows to the DataGrid.

Can​User​Delete​Rows

Gets or sets a value that indicates whether the user can delete rows from the DataGrid.

Can​User​Reorder​Columns

Gets or sets a value that indicates whether the user can change the column display order by dragging column headers with the mouse.

Can​User​Resize​Columns

Gets or sets a value that indicates whether the user can adjust the width of columns by using the mouse.

Can​User​Resize​Rows

Gets or sets a value that indicates whether the user can adjust the height of rows by using the mouse.

Can​User​Sort​Columns

Gets or sets a value that indicates whether the user can sort columns by clicking the column header.

Cells​Panel​Horizontal​Offset

Gets the horizontal offset for the DataGridCellsPanel.

Cell​Style

Gets or sets the style applied to all cells in the DataGrid.

Clipboard​Copy​Mode

Gets or sets a value that indicates how content is copied to the clipboard.

Column​Header​Height

Gets or sets the height of the column headers row.

Column​Header​Style

Gets or sets the style applied to all column headers in the DataGrid.

Columns

Gets a collection that contains all the columns in the DataGrid.

Column​Width

Gets or sets the standard width and sizing mode of columns and headers in the DataGrid.

Current​Cell

Gets or sets the cell that has focus.

Current​Column

Gets or sets the column that contains the current cell.

Current​Item

Gets the data item bound to the row that contains the current cell.

Delete​Command

Represents the command that indicates the intention to delete the current row.

Drag​Indicator​Style

Gets or sets the style that is used when rendering the drag indicator that is displayed while dragging a column header.

Drop​Location​Indicator​Style

Gets or sets the style that is applied to indicate the drop location when dragging a column header.

Enable​Column​Virtualization

Gets or sets a value that indicates whether column virtualization is enabled.

Enable​Row​Virtualization

Gets or sets a value that indicates whether row virtualization is enabled.

Focus​Border​Brush​Key

Gets the key that references the default border brush for a focused cell.

Frozen​Column​Count

Gets or sets the number of non-scrolling columns.

Grid​Lines​Visibility

Gets or sets a value that indicates which grid lines are shown.

Handles​Scrolling

Gets a value that indicates whether the DataGrid supports custom keyboard scrolling.

Headers​Visibility

Gets or sets the value that specifies the visibility of the row and column headers.

Headers​Visibility​Converter

Gets the converter that converts a DataGridHeadersVisibility to a Visibility.

Horizontal​Grid​Lines​Brush

Gets or sets the brush that is used to draw the horizontal grid lines.

Horizontal​Scroll​Bar​Visibility

Gets or sets a value that indicates how horizontal scroll bars are displayed in the DataGrid.

Is​Read​Only

Gets or sets a value that indicates whether the user can edit values in the DataGrid.

Max​Column​Width

Gets or sets the maximum width constraint of the columns and headers in the DataGrid.

Min​Column​Width

Gets or sets the minimum width constraint of the columns and headers in the DataGrid.

Min​Row​Height

Gets or sets the minimum height constraint of the rows and headers in the DataGrid.

New​Item​Margin

Gets or sets the margin for the new item row.

Non​Frozen​Columns​Viewport​Horizontal​Offset

Gets the horizontal offset of the scrollable columns in the view port.

Row​Background

Gets or sets the default brush for the row background.

Row​Details​Scrolling​Converter

Gets the converter that converts a Boolean value to a SelectiveScrollingOrientation.

Row​Details​Template

Gets or sets the template that is used to display the row details.

Row​Details​Template​Selector

Gets or sets the template selector that is used for the row details.

Row​Details​Visibility​Mode

Gets or sets a value that indicates when the details section of a row is displayed.

Row​Header​Actual​Width

Gets the rendered width of the row headers column.

Row​Header​Style

Gets or sets the style applied to all row headers.

Row​Header​Template

Gets or set the template for the row headers.

Row​Header​Template​Selector

Gets or sets the template selector for row headers.

Row​Header​Width

Gets or sets the width of the row header column.

Row​Height

Gets or sets the suggested height for all rows.

Row​Style

Gets or sets the style applied to all rows.

Row​Style​Selector

Gets or sets the style selector for the rows.

Row​Validation​Error​Template

Gets or sets the template that is used to visually indicate an error in row validation.

Row​Validation​Rules

Gets the rules that are used to validate the data in each row.

Select​All​Command

Represents the command that indicates the intention to select all cells in the DataGrid.

Selected​Cells

Gets the list of cells that are currently selected.

Selection​Mode

Gets or sets a value that indicates how rows and cells are selected in the DataGrid.

Selection​Unit

Gets or sets a value that indicates whether rows, cells, or both can be selected in the DataGrid.

Vertical​Grid​Lines​Brush

Gets or sets the brush that is used to draw the vertical grid lines.

Vertical​Scroll​Bar​Visibility

Gets or sets a value that indicates how vertical scroll bars are displayed in the DataGrid.

Methods

Begin​Edit(​Routed​Event​Args)

Invokes the BeginEdit() command, which will place the current cell or row into edit mode.

Begin​Edit()

Invokes the BeginEdit() command, which will place the current cell or row into edit mode.

Cancel​Edit()

Invokes the CancelEditCommand command for the cell or row currently in edit mode.

Cancel​Edit(​Data​Grid​Editing​Unit)

Invokes the CancelEditCommand command for the specified cell or row in edit mode.

Clear​Container​For​Item​Override(​Dependency​Object, ​Object)

Unloads the row for the specified item.

Clear​Details​Visibility​For​Item(​Object)

Clears the DetailsVisibility property for the DataGridRow that represents the specified data item.

Column​From​Display​Index(​Int32)

Gets the DataGridColumn at the specified index.

Commit​Edit()

Invokes the CommitEditCommand command for the cell or row currently in edit mode.

Commit​Edit(​Data​Grid​Editing​Unit, ​Boolean)

Invokes the CommitEditCommand command for the specified cell or row currently in edit mode.

Generate​Columns(​IItem​Properties)

Generates columns for the specified properties of an object.

Get​Container​For​Item​Override()

Instantiates a new DataGridRow.

Get​Details​Visibility​For​Item(​Object)

Gets the DetailsVisibility property for the DataGridRow that represents the specified data item.

Is​Item​Its​Own​Container​Override(​Object)

Determines if an item is a DataGridRow.

Measure​Override(​Size)

Determines the desired size of the DataGrid.

On​Adding​New​Item(​Adding​New​Item​Event​Args)

Raises the AddingNewItem event.

On​Apply​Template()

Invoked whenever application code or internal processes call ApplyTemplate().

On​Auto​Generated​Columns(​Event​Args)

Raises the AutoGeneratedColumns event.

On​Auto​Generating​Column(​Data​Grid​Auto​Generating​Column​Event​Args)

Raises the AutoGeneratingColumn event.

On​Beginning​Edit(​Data​Grid​Beginning​Edit​Event​Args)

Raises the BeginningEdit event.

On​Can​Execute​Begin​Edit(​Can​Execute​Routed​Event​Args)

Provides handling for the CanExecute event associated with the BeginEditCommand command.

On​Can​Execute​Cancel​Edit(​Can​Execute​Routed​Event​Args)

Provides handling for the CanExecute event associated with the CancelEditCommand command.

On​Can​Execute​Commit​Edit(​Can​Execute​Routed​Event​Args)

Provides handling for the CanExecute event associated with the CommitEditCommand command.

On​Can​Execute​Copy(​Can​Execute​Routed​Event​Args)

Provides handling for the CanExecute event associated with the Copy command.

On​Can​Execute​Delete(​Can​Execute​Routed​Event​Args)

Provides handling for the CanExecute event associated with the DeleteCommand command.

On​Cell​Edit​Ending(​Data​Grid​Cell​Edit​Ending​Event​Args)

Raises the CellEditEnding event.

On​Column​Display​Index​Changed(​Data​Grid​Column​Event​Args)

Raises the ColumnDisplayIndexChanged event.

On​Column​Header​Drag​Completed(​Drag​Completed​Event​Args)

Raises the ColumnHeaderDragCompleted event.

On​Column​Header​Drag​Delta(​Drag​Delta​Event​Args)

Raises the ColumnHeaderDragDelta event.

On​Column​Header​Drag​Started(​Drag​Started​Event​Args)

Raises the ColumnHeaderDragStarted event.

On​Column​Reordered(​Data​Grid​Column​Event​Args)

Raises the ColumnReordered event.

On​Column​Reordering(​Data​Grid​Column​Reordering​Event​Args)

Raises the ColumnReordering event.

On​Context​Menu​Opening(​Context​Menu​Event​Args)

Selects a cell if its context menu is opened.

On​Copying​Row​Clipboard​Content(​Data​Grid​Row​Clipboard​Event​Args)

Raises the CopyingRowClipboardContent event.

On​Create​Automation​Peer()

Returns the automation peer for this DataGrid.

On​Current​Cell​Changed(​Event​Args)

Raises the CurrentCellChanged event.

On​Executed​Begin​Edit(​Executed​Routed​Event​Args)

Provides handling for the Executed event associated with the BeginEditCommand command.

On​Executed​Cancel​Edit(​Executed​Routed​Event​Args)

Provides handling for the Executed event associated with the CancelEditCommand command.

On​Executed​Commit​Edit(​Executed​Routed​Event​Args)

Provides handling for the Executed event associated with the CommitEditCommand command.

On​Executed​Copy(​Executed​Routed​Event​Args)

Provides handling for the Executed event associated with the Copy command.

On​Executed​Delete(​Executed​Routed​Event​Args)

Provides handling for the Executed event associated with the DeleteCommand command.

On​Initializing​New​Item(​Initializing​New​Item​Event​Args)

Raises the InitializingNewItem event.

On​Is​Mouse​Captured​Changed(​Dependency​Property​Changed​Event​Args)

Called when the IsMouseCaptured property changes on this element.

On​Items​Changed(​Notify​Collection​Changed​Event​Args)

Performs column auto generation and updates validation flags when items change.

On​Items​Source​Changed(​IEnumerable, ​IEnumerable)

Invoked when the ItemsSource property changes.

On​Key​Down(​Key​Event​Args)

Invoked when the KeyDown event is received.

On​Loading​Row(​Data​Grid​Row​Event​Args)

Raises the LoadingRow event.

On​Loading​Row​Details(​Data​Grid​Row​Details​Event​Args)

Raises the LoadingRowDetails event.

On​Mouse​Move(​Mouse​Event​Args)

Updates the collection of items that are selected due to the user dragging the mouse in the DataGrid.

On​Preparing​Cell​For​Edit(​Data​Grid​Preparing​Cell​For​Edit​Event​Args)

Raises the PreparingCellForEdit event.

On​Row​Details​Visibility​Changed(​Data​Grid​Row​Details​Event​Args)

Raises the RowDetailsVisibilityChanged event.

On​Row​Edit​Ending(​Data​Grid​Row​Edit​Ending​Event​Args)

Raises the RowEditEnding event.

On​Selected​Cells​Changed(​Selected​Cells​Changed​Event​Args)

Raises the SelectedCellsChanged event.

On​Selection​Changed(​Selection​Changed​Event​Args)

Invoked when the selection changes.

On​Sorting(​Data​Grid​Sorting​Event​Args)

Raises the Sorting event.

On​Template​Changed(​Control​Template, ​Control​Template)

Called whenever the template of the DataGrid changes.

On​Text​Input(​Text​Composition​Event​Args)

Provides class handling for the TextInput routed event.

On​Unloading​Row(​Data​Grid​Row​Event​Args)

Raises the UnloadingRow event.

On​Unloading​Row​Details(​Data​Grid​Row​Details​Event​Args)

Raises the UnloadingRowDetails event.

Prepare​Container​For​Item​Override(​Dependency​Object, ​Object)

Prepares a new row for the specified item.

Scroll​Into​View(​Object)

Scrolls the DataGrid vertically to display the row for the specified data item.

Scroll​Into​View(​Object, ​Data​Grid​Column)

Scrolls the DataGrid vertically and horizontally to display a cell for the specified data item and column.

Select​All​Cells()

Selects all the cells in the DataGrid.

Set​Details​Visibility​For​Item(​Object, ​Visibility)

Sets the value of the DetailsVisibility property for the DataGridRow that contains the specified object.

Unselect​All​Cells()

Unselects all the cells in the DataGrid.

Events

Adding​New​Item

Occurs before a new item is added to the DataGrid.

Auto​Generated​Columns

Occurs when auto generation of all columns is completed.

Auto​Generating​Column

Occurs when an individual column is auto-generated.

Beginning​Edit

Occurs before a row or cell enters edit mode.

Cell​Edit​Ending

Occurs before a cell edit is committed or canceled.

Column​Display​Index​Changed

Occurs when the DisplayIndex property on one of the columns changes.

Column​Header​Drag​Completed

Occurs when the user releases a column header after dragging it by using the mouse.

Column​Header​Drag​Delta

Occurs every time the mouse position changes while the user drags a column header.

Column​Header​Drag​Started

Occurs when the user begins dragging a column header by using the mouse.

Column​Reordered

Occurs when a column moves to a new position in the display order.

Column​Reordering

Occurs before a column moves to a new position in the display order.

Copying​Row​Clipboard​Content

Occurs after the default row content is prepared.

Current​Cell​Changed

Occurs when the value of the CurrentCell property has changed.

Initializing​New​Item

Occurs when a new item is created.

Loading​Row

Occurs after a DataGridRow is instantiated, so that you can customize it before it is used.

Loading​Row​Details

Occurs when a new row details template is applied to a row.

Preparing​Cell​For​Edit

Occurs when a cell enters edit mode.

Row​Details​Visibility​Changed

Occurs when the visibility of a row details element changes.

Row​Edit​Ending

Occurs before a row edit is committed or canceled.

Selected​Cells​Changed

Occurs when the SelectedCells collection changes.

Sorting

Occurs when a column is being sorted.

Unloading​Row

Occurs when a DataGridRow object becomes available for reuse.

Unloading​Row​Details

Occurs when a row details element becomes available for reuse.