WPF - DataGridCheckBoxColumn Issues

In WPF, how can I have a DataGridCheckBoxColumn that allows me to click the checkboxes without having to select the row first. It's weird that when I click the checkbox it selects the row rather than just clicking the checkbox I have this which seems to work, but it doesn't seem to update the value in the model when the checkbox is clicked. It only gets updated when I click the cell and click away. How can I fix it so that when I click the checkbox it updates the model?
<DataGridTemplateColumn Header="Enabled" MinWidth="100" Width="100">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding Enabled, Mode=TwoWay}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Enabled" MinWidth="100" Width="100">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding Enabled, Mode=TwoWay}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
3 Replies
Mayor McCheese
Try and add this style to your data grid
<Style TargetType="DataGridCell">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="IsEditing" Value="True" />
</Trigger>
</Style.Triggers>
</Style>
<Style TargetType="DataGridCell">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="IsEditing" Value="True" />
</Trigger>
</Style.Triggers>
</Style>
nathanAjacobs
nathanAjacobsOP4w ago
Is there a way to apply that only to a specific column though? I wouldn't want that applied to text columns
Mayor McCheese
See if it works at all first Then you can use the style with a key probably
Want results from more Discord servers?
Add your server