Files
docs-desktop/dotnet-desktop-guide/framework/wpf/controls/how-to-create-listviewitems-with-a-checkbox.md
T
Andy De George da363692ff Initial WPF content migrated (#17)
* Reset branch for WPF changes

* Convert BMP to PNG; fix link-out-of-scope err

* Add snippets for WPF... 6794 files!!!!

* Add missing snippets

* update file updated between migration

* Fix paths to include

* update breadcrumb and toc

* fix index links

* fix index links

* fix index links

* fix markdown
2020-09-04 09:46:28 -07:00

2.4 KiB

title, ms.date, helpviewer_keywords, ms.assetid
title ms.date helpviewer_keywords ms.assetid
How to: Create ListViewItems with a CheckBox 03/30/2017
controls [WPF], ListView
controls [WPF], CheckBox
ListView controls [WPF], CheckBox controls
CheckBox control [WPF], ListView control
f6d66c7f-906c-4f65-a55a-0ede9d00e26a

How to: Create ListViewItems with a CheckBox

This example shows how to display a column of xref:System.Windows.Controls.CheckBox controls in a xref:System.Windows.Controls.ListView control that uses a xref:System.Windows.Controls.GridView.

Example

To create a column that contains xref:System.Windows.Controls.CheckBox controls in a xref:System.Windows.Controls.ListView, create a xref:System.Windows.DataTemplate that contains a xref:System.Windows.Controls.CheckBox. Then set the xref:System.Windows.Controls.GridViewColumn.CellTemplate%2A of a xref:System.Windows.Controls.GridViewColumn to the xref:System.Windows.DataTemplate.

The following example shows a xref:System.Windows.DataTemplate that contains a xref:System.Windows.Controls.CheckBox. The example binds the xref:System.Windows.Controls.Primitives.ToggleButton.IsChecked%2A property of the xref:System.Windows.Controls.CheckBox to the xref:System.Windows.Controls.ListBoxItem.IsSelected%2A property value of the xref:System.Windows.Controls.ListViewItem that contains it. Therefore, when the xref:System.Windows.Controls.ListViewItem that contains the xref:System.Windows.Controls.CheckBox is selected, the xref:System.Windows.Controls.CheckBox is checked.

[!code-xamlListViewChkBox#CheckBoxDataTemplate]

The following example shows how to create a column of xref:System.Windows.Controls.CheckBox controls. To make the column, the example sets the xref:System.Windows.Controls.GridViewColumn.CellTemplate%2A property of the xref:System.Windows.Controls.GridViewColumn to the xref:System.Windows.DataTemplate.

[!code-xamlListViewChkBox#GridViewColumnCheckBox]

See also