How to: Create ListViewItems with a CheckBox

This example shows how to display a column of CheckBox controls in a ListView control that uses a GridView.


To create a column that contains CheckBox controls in a ListView, create a DataTemplate that contains a CheckBox. Then set the CellTemplate of a GridViewColumn to the DataTemplate.

The following example shows a DataTemplate that contains a CheckBox. The example binds the IsChecked property of the CheckBox to the IsSelected property value of the ListViewItem that contains it. Therefore, when the ListViewItem that contains the CheckBox is selected, the CheckBox is checked.

<DataTemplate x:Key="FirstCell">
  <StackPanel Orientation="Horizontal">
    <CheckBox IsChecked="{Binding Path=IsSelected, 
      RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}}"/>

The following example shows how to create a column of CheckBox controls. To make the column, the example sets the CellTemplate property of the GridViewColumn to the DataTemplate.

<GridViewColumn CellTemplate="{StaticResource FirstCell}" 

See also