The DataGrid control enables you to display and edit data from many different sources, such as from a SQL database, LINQ query, or any other bindable data source. For more information, see Binding Sources Overview.
Columns can display text, controls, such as a ComboBox, or any other WPF content, such as images, buttons, or any content contained in a template. You can use a DataGridTemplateColumn to display data defined in a template. The following table lists the column types that are provided by default.
Generated Column Type
DataGrid can be customized in appearance, such as cell font, color, and size. DataGrid supports all styling and templating functionality of other WPF controls. DataGrid also includes default and customizable behaviors for editing, sorting, and validation.
The following table lists some of the common tasks for DataGrid and how to accomplish them. By viewing the related API, you can find more information and sample code.
Alternating background colors
Define cell and row selection behavior
Customize the visual appearance of headers, cells, and rows
Set sizing options
Access selected items
Customize end-user interactions
Cancel or change auto-generated columns
Handle the AutoGeneratingColumn event.
Freeze a column
Use XML data as the data source
Bind the ItemsSource on the DataGrid to the XPath query that represents 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.
Describes how to set up a new WPF project, add an Entity Framework Element, set the source, and display the data in a DataGrid.
Describes how to create row details for a DataGrid.
Describes how to validate values in DataGrid cells and rows, and display validation feedback.
Describes how to interact with the DataGrid control by using the keyboard and mouse.
Describes how to view data in a DataGrid in different ways by grouping, sorting, and filtering the data.
Describes how to control absolute and automatic sizing in the DataGrid.