This question already has an answer here:
I have a DataGrid with a Checkbox & other Textbox.
<DataGrid AutoGenerateColumns="False" Height="170" Name="dataGrid1" Width="527" OpacityMask="#FF161A1A" BorderBrush="#FFB7B39D" Background="LightYellow" RowBackground="LightGray" AlternatingRowBackground="#FFFFFFF5" BorderThickness="10" CanUserResizeRows="False" CanUserReorderColumns="False" CanUserResizeColumns="True" CanUserSortColumns="False" FontFamily="Segoe UI" FontSize="13" CanUserAddRows="False">
<DataGrid.Columns>
<DataGridCheckBoxColumn Header="" Binding="{Binding BoolProperty, Mode=TwoWay}" />
<DataGridTextColumn Header="" Binding="{Binding header}" MinWidth="108" IsReadOnly="True" />
<DataGridTextColumn Header="Number of Cases" Binding="{Binding cases}" >
<DataGridTextColumn.EditingElementStyle>
<Style TargetType="TextBox">
<Setter Property="IsEnabled" Value="{Binding Path=BoolProperty, Mode=TwoWay}" />
</Style>
</DataGridTextColumn.EditingElementStyle>
</DataGridTextColumn>
The checkboxcolumn is bind to a "BoolProperty". I want is Textbox "Number of Cases" to be disabled if the BoolProperty is false and enable if the BoolProperty is true. I tried adding the IsEnabled in TExtBox, but it doesn't work. Where am I going wrong ?
I used the
LoadingRow
event of myDataGrid
in one project to check specific status. Maybe something like this could help:In your case you can enable/disable your cell in the if-else contruct.
Hope it helps.
For an XAML only approach, use a template column instead.
IsReadOnly
isn't bindable at the cell level. Since that link doesn't provide implementation, I will.