title: DataGrid with a checkbox column to allow the user to select rows?
body: <p>Regards,</p>
  
  <p>I have a <code>DataGrid</code> with a checkbox column to allow the user to select rows, a "select all" checkbox in the column header, and a "select all" checkbox in the group header.</p>
  
  <p>XAML: </p>
  
  <pre><code>&lt;DataGrid CanUserAddRows="True"  CanUserDeleteRows="True" Grid.ColumnSpan="2"     Margin="7,4,8,41" Name="customerDataGrid" Grid.Row="3" ItemsSource="{Binding}"  ColumnHeaderStyle="{Binding Source={StaticResource TabControlInnerBorder}}" DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=DataGrid,  AncestorLevel=1}}"&gt;
      &lt;DataGrid.GroupStyle&gt;
          &lt;GroupStyle&gt;
              &lt;GroupStyle.HeaderTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;StackPanel&gt;
                          &lt;TextBlock Text="{Binding Path=City}" FontWeight="Bold" Padding="3"/&gt;
                      &lt;/StackPanel&gt;
                  &lt;/DataTemplate&gt;
              &lt;/GroupStyle.HeaderTemplate&gt;
              &lt;GroupStyle.ContainerStyle&gt;
                  &lt;Style TargetType="{x:Type GroupItem}"&gt;
                      &lt;Setter Property="Template"&gt;
                          &lt;Setter.Value&gt;
                              &lt;ControlTemplate TargetType="{x:Type GroupItem}"&gt;
                                  &lt;Expander&gt;
                                      &lt;Expander.Header&gt;
                                          &lt;StackPanel Orientation="Horizontal"&gt;
                                              &lt;TextBlock  Text="{Binding Path=Name}"   /&gt;
                                              &lt;TextBlock  Text="{Binding Path=ItemCount}" /&gt;
                                              &lt;TextBlock  Text="Emp(s)" /&gt;
                                              &lt;CheckBox  Content="{Binding Path=Name}" ClickMode="Press" Checked="CheckBox_Checked"  /&gt;
                                          &lt;/StackPanel&gt;
                                      &lt;/Expander.Header&gt;
                                      &lt;ItemsPresenter /&gt;
                                  &lt;/Expander&gt;
                              &lt;/ControlTemplate&gt;
                          &lt;/Setter.Value&gt;
                     &lt;/Setter&gt;
                 &lt;/Style&gt;
             &lt;/GroupStyle.ContainerStyle&gt;
         &lt;/GroupStyle&gt;
     &lt;/DataGrid.GroupStyle&gt;
  &lt;/DataGrid&gt;
  </code></pre>
  
  <hr>
  
  <p><strong>.CS</strong></p>
  
  <pre><code> private ICollectionView defaultView1;
   public main1_windows()
   {
       InitializeComponent();
       List&lt;Employ&gt; empl = new List&lt;Employ&gt;();
       empl = LoadData();
       this.defaultView1 = CollectionViewSource.GetDefaultView(empl);
       this.defaultView1.GroupDescriptions.Add(new PropertyGroupDescription  ("dep"));
       this.defaultView1.Filter = new Predicate&lt;object&gt;(Contains1);  
   }
  </code></pre>
  
  <hr>
  
  <pre><code>public bool Contains1(object de)
  {
      Employ order = de as Employ;
      //Return members whose Orders have not been filled 
      return (order.Name.ToString().Contains(textBox4.Text).Equals(true));
  }
  </code></pre>
  
  <hr>
  
  <pre><code>private List&lt;Employ&gt; LoadData()
  {
      List&lt;Employ&gt; employ = new List&lt;Employ&gt;();
      employ.Add(new Employ()
          {
              ID = 2000,
              Name = "moh",
              DOB = new DateTime(1985, 5, 15),
              dep="pro",
              IsNew = false 
          });
      employ.Add(new Employ()
          {
              ID = 3000,
              Name = "jac",
              DOB = new DateTime(1985, 5, 15),
              dep="pro",
              IsNew = false 
          });
      employ.Add(new Employ()
          {
              ID = 4000,
              Name = "ahmad",
              DOB = new DateTime(1985, 5, 15),
              dep="admin",
               IsNew = false 
          });
      return employ;
  }
  public class Employ
  {
      public int ID { get; set; }
      public string Name { get; set; }
      public DateTime DOB { get; set; }
      public string dep { get; set; } 
      public bool IsNew { get; set; }
  }
  
  private void textBox4_TextChanged(object sender, TextChangedEventArgs e)
  {
      this.defaultView1.Filter = new Predicate&lt;object&gt;(Contains1);
  }
  </code></pre>
  
  <hr>
  
  <pre><code>private void CheckBox_Checked(object sender, RoutedEventArgs e)
  {
      // I want when the apical true check box in the group all the rows in this group check box true value;
  }
  </code></pre>
  
  <hr>
  
  <p><img src="https://i.stack.imgur.com/oVO4C.png" alt="enter image description here"></p>
  
  <p>How I Can Select all rows in group<br>
  Thanks .</p>