Skip to main content
A newer version of this page is available. .

How to: Display a Check Box within Column Headers

  • 3 minutes to read

This example demonstrates how to display a check box within column headers. If the check box is checked, the corresponding column is made read-only. Uncheck the check box to allow column values to be edited.

Tip

Starting with v18.2, you can set the ColumnBase.ShowCheckBoxInHeader property to true to show a check-box for a boolean column.

<Window x:Class="DXGrid_ShowCheckBoxInColumnHeaders.Window1" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors" 
        xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid" 
        Title="Window1" Height="300" Width="515">
  <Window.Resources>
     <DataTemplate x:Key="ReadOnlyHeaderTemplate">
         <dxe:CheckEdit IsChecked="{Binding Column.ReadOnly, Mode=TwoWay}" />
     </DataTemplate>
  </Window.Resources>
  <Grid>
        <dxg:GridControl x:Name="grid" AutoGenerateColumns="AddNew" ItemsSource="{Binding ListPerson}">
         <dxg:GridControl.View>
             <dxg:TableView AutoWidth="True" NavigationStyle="Cell" 
                            ColumnHeaderCustomizationAreaTemplate="{StaticResource ReadOnlyHeaderTemplate}" />
         </dxg:GridControl.View>
     </dxg:GridControl>
  </Grid>
</Window>
// Developer Express Code Central Example:
// How to display a check box within column headers
// 
// This example demonstrates how to display a check box within column headers. If
// the check box is checked, the corresponding column is made read-only. Uncheck
// the check box to allow column values to be edited.
// 
// You can find sample updates and versions for different programming languages here:
// http://www.devexpress.com/example=E1517

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DevExpress.Xpf.Editors;
using DevExpress.Xpf.Grid;

namespace DXGrid_ShowCheckBoxInColumnHeaders {
    public partial class Window1 : Window {
        public Window1() {
            InitializeComponent();
            CreateList();
            DataContext = this;

        }
        public List<Person> ListPerson { get; set; }
        void CreateList() {
            ListPerson = new List<Person>();
            for (int i = 0; i < 10; i++) {
                ListPerson.Add(new Person(i));
            }
        }
    }

    public class Person {
        public Person(int i) {
            FirstName = "FirstName" + i;
            LastName = "LastName" + i;
            Age = i * 10;
        }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public int Age { get; set; }


    }
}