Hi all,
In my WPF application, I need to get all the selected rows of a datagrid on the click of a button which is outside the datagrid.I am using a checkbox in the row header template to select or deselect a row. Below is the small code snippet of my datagrid xaml. Please can any one help me out in fetching all the selected rows on the click of a button. I have searched a lot on google, but all the links are regarding fethcing selected items on "dataGrid_SelectionChanged" event, which is very easy.
<my:DataGrid AutoGenerateColumns="False" SelectionChanged="dataGrid_SelectionChanged" Initialized="DataGrid_Initialized" >
<my:DataGrid.RowHeaderTemplate>
<DataTemplate>
<Grid>
<CheckBox IsChecked="{Binding Path=IsSelected, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type my:DataGridRow}}}"/>
</Grid>
</DataTemplate>
</my:DataGrid.RowHeaderTemplate>
<my:DataGrid.Columns>
<my:DataGridTemplateColumn Width="160" Header="Media Status" >
<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="5,8,5,0">
<TextBlock>
<TextBlock.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding MediaStatus}" Value="False">
<Setter Property="TextBlock.Text" Value="Not Processed" />
</DataTrigger>
<DataTrigger Binding="{Binding MediaStatus}" Value="True">
<Setter Property="TextBlock.Text" Value="Processed" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</StackPanel>
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
</my:DataGridTemplateColumn>
</my:DataGrid.Columns>
</my:DataGrid>
Thanks
Anurag