Reputation: 2022
I am trying to select the value from the datagrid checkbox (whether it is checked or unchecked) and second column(UserName). Here is the datagrid code.
<DataGrid AutoGenerateColumns="False" Name="enableDataGrid" ItemsSource="{Binding}" Margin="0,0,0,81">
<DataGrid.Columns>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox HorizontalAlignment="Center"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="User Name" Binding="{Binding Path=uName}"/>
</DataGrid.Column>
</DataGrid>
How should i achieve it ?Please suggest.
Upvotes: 0
Views: 4253
Reputation: 12410
Bind the checkbox to a property in your itemsource then you can get the selected row from the datagrid
<CheckBox HorizontalAlignment="Center" IsChecked="{Binding myBool}"/>
MyDatagridItem item = MyDatagrid.SelectedItem as MyDatagridItem
if(item.myBool == true){
...
}
Upvotes: 1
Reputation: 9214
Use DataGridCheckBoxColumn
instead:
<DataGridCheckBoxColumn Binding="{Binding IsChecked}" />
Upvotes: 1