Silverlight / WPF - Check All check boxes inside datagrid by selecting all checkbox out side the datagrid

Asked By gopal krish on 12-Jun-12 12:55 AM
Jitendra Faye replied to gopal krish on 12-Jun-12 12:58 AM
reference from-

http://stackoverflow.com/questions/10225860/unchecked-any-one-checkbox-of-celltemplate-from-the-list-i-want-to-uncheck-the
solutio
n-

Here is the control template for the header

<Style x:Key="checkBoxHeaderStyle"
               TargetType="{x:Type w:DataGridColumnHeader}">
                            <Setter Property="Template">
                <Setter.Value>
                  <ControlTemplate TargetType="{x:Type w:DataGridColumnHeader}">
                    <CheckBox
                        IsChecked="{Binding  Path = IsSelectAllChecked , Mode = TwoWay}"/>
                  </ControlTemplate>
                </Setter.Value>
              </Setter>
            </Style>

Here is the template column applying the style

<w:DataGridTemplateColumn MinWidth="50"
                        HeaderStyle="{DynamicResource checkBoxHeaderStyle}"
                        CanUserResize="False">
              <w:DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                  <CheckBox Name="selectAllCheckBox"
                                  HorizontalAlignment="Center"                        Margin="1,0,0,0"                                                VerticalAlignment="Center"
                      IsChecked="{Binding Path = IsSelected, Mode=TwoWay}" />
                </DataTemplate>
              </w:DataGridTemplateColumn.CellTemplate>
            </w:DataGridTemplateColumn>

The is selected property is

public bool IsSelected
{
    get { return selected; }
    set { selected = value;
    OnPropertyChanged("IsSelected");
    }
}

For the header check box

public bool IsSelectAllChecked
      {
        get { return isSelectAllChecked; }
        set
        {
          isSelectAllChecked = value;
          base.OnPropertyChanged("IsSelectAllChecked");
//Call the method which sets the IsSelected property to true of false, based on value
          SetAllCheckBoxesState(value);
        }

    }

Hope this will help you.
gopal krish replied to gopal krish on 12-Jun-12 01:00 AM
hi..

i have a datgrid which contains checkbox.
i also have a checkbox outside the datagrid.
if i checked outside checkbox then the datagird checkboxes will be in checked mode and also i need to get the checked rows infromation in order to do database operations..

how to do this..

need ur suggestions with examples..

regards
gopal.s