WPF DataGrid Introduction Tutorial

WPF DataGrid control is used for display and edit tabular data in rows and columns. DataGrid control is introduced in .NET 4.0.

DataGrid control main features are:

  1. Bind to any collection that implements IEnumerable interface
  2. Auto generate data rows and columns based on bounded data.
  3. Provides different row selection-modes: Single/Extended
  4. Provides options for grouping, sorting, filtering columns
  5. Validation support
  6. UI Virtualization support for both rows and columns
  7. Frozen Columns
  8. RowDetails template for showing extra content of row
  9. Editing support for editing rows and columns

WPF DataGrid looks like WPF ListView Control as both display data in tabular format. But there are some major differences.

Difference between WPF DataGrid and WPF ListView

There are four main differences between both.

  1. Editing support
  2. Auto Generate Columns
  3. Row Details
  4. Frozen Columns

Editing support

WPF DataGrid provides inbuilt support for directly editing data. But ListView shows only read-only view of data.

Auto Generate Columns

WPF DataGrid automatically generate columns for display from the data source you have bind through ItemsSource property. But in ListView, you have to manually define the columns to display.

Row Details

WPF DataGrid provides you an option for display additional details of row which you can show/hide based on setting of RowDetailsVisibilityMode property. But WPF ListView does not provide any option for showing additional details of row.

Frozen Columns

DataGrid lets you defines some columns to be freeze so that if you move in your DataGrid, frozen columns will not move.