WPF DataGrid Delete Data

Jul 15, 2011 at 10:13 AM

I having problem to delete data from datagrid.How to delete data based on check box selection.Single selection and All

        <DataGrid x:Name="Dg1" AutoGenerateColumns="False" ItemsSource="{Binding}" CanUserAddRows="False" LoadingRow="Dg1_LoadingRow_1" Loaded="Dg1_Loaded_1" RowEditEnding="Dg1_RowEditEnding" Margin="0,0,0,117">
            <DataGrid.Columns>
                <DataGridTemplateColumn Header="Name">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Name}"></TextBlock>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn>
                    <DataGridTemplateColumn.HeaderStyle>
                        <Style TargetType="{x:Type DataGridColumnHeader}">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
                                        <CheckBox x:Name="CHK_SelectAll" Content="Select All" Click="CHK_SelectAll_Click" HorizontalAlignment="Center" VerticalAlignment="Center"></CheckBox>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </DataGridTemplateColumn.HeaderStyle>
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox x:Name="Chk" Tag="{Binding ID}" Click="Chk_Click"></CheckBox>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

<DataGrid x:Name="Dg1" AutoGenerateColumns="False" ItemsSource="{Binding}" CanUserAddRows="False" LoadingRow="Dg1_LoadingRow_1" Loaded="Dg1_Loaded_1" RowEditEnding="Dg1_RowEditEnding" Margin

="0,0,0,117">

 

<DataGrid.Columns

>

 

<DataGridTemplateColumn Header

="Name">

 

<DataGridTemplateColumn.CellTemplate

>

 

<DataTemplate

>

 

<TextBlock Text="{Binding Name}"></TextBlock

>

 

</DataTemplate

>

 

</DataGridTemplateColumn.CellTemplate

>

 

</DataGridTemplateColumn

>

 

<DataGridTemplateColumn

>

 

<DataGridTemplateColumn.HeaderStyle

>

 

<Style TargetType="{x:Type DataGridColumnHeader

}">

 

<Setter Property

="Template">

 

<Setter.Value

>

 

<ControlTemplate TargetType="{x:Type DataGridColumnHeader

}">

 

<CheckBox x:Name="CHK_SelectAll" Content="Select All" Click="CHK_SelectAll_Click" HorizontalAlignment="Center" VerticalAlignment="Center"></CheckBox

>

 

</ControlTemplate

>

 

</Setter.Value

>

 

</Setter

>

 

</Style

>

 

</DataGridTemplateColumn.HeaderStyle

>

 

<DataGridTemplateColumn.CellTemplate

>

 

<DataTemplate

>

 

<CheckBox x:Name="Chk" Tag="{Binding ID}" Click="Chk_Click"></CheckBox

>

 

</DataTemplate

>

 

</DataGridTemplateColumn.CellTemplate

>

 

</DataGridTemplateColumn

>

 

</DataGrid.Columns

>

 

</DataGrid

>