0

I am using an ICollectionView of an ObservableCollection to display data in a DataGrid. Each entry consists of an IsEnabled property (displayed in a DataGridCheckBoxColumn) and two Integer values (each in one DataGridTextColumn). When the IsEnabled is false, the entire row get disabled using this style:

<Style TargetType="{x:Type DataGridRow}">
    <Style.Triggers>
        <DataTrigger Binding="{Binding IsEnabled}" Value="False">
            <Setter Property="IsEnabled" Value="False"/>
        </DataTrigger>
    </Style.Triggers>
</Style>

The datagrid looks like this:

<DataGrid 
       CanUserAddRows="False" 
       CanUserDeleteRows="False" 
       CanUserReorderColumns="false"
       AutoGenerateColumns="false" 
       IsSynchronizedWithCurrentItem="True"
       ItemsSource="{Binding Path=ListView, UpdateSourceTrigger=PropertyChanged}">
        <DataGrid.Columns>
            <DataGridCheckBoxColumn Binding="{Binding Path=IsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
            </DataGridCheckBoxColumn>
            <DataGridTextColumn Header="Name" Width="*" IsReadOnly="True"
                                Binding="{Binding Path=Name, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}">
                <DataGridTextColumn.ElementStyle>
                    <Style>
                        <Setter Property="TextBlock.TextAlignment" Value="Left"/>
                    </Style>
                </DataGridTextColumn.ElementStyle>
            </DataGridTextColumn>
            <DataGridTextColumn Width="*" Binding="{Binding Path=Min, Mode=TwoWay}">
                <DataGridTextColumn.Header>
                        <TextBlock HorizontalAlignment="center" Text="Min"/>
                </DataGridTextColumn.Header>                    
            </DataGridTextColumn>
            <DataGridTextColumn  Width="*" Binding="{Binding Path=Max, Mode=TwoWay}">
                <DataGridTextColumn.Header>
                        <TextBlock HorizontalAlignment="center" Text="Max"/>
                </DataGridTextColumn.Header>                    
            </DataGridTextColumn>
        </DataGrid.Columns>
    </DataGrid>

I encounter this strange behaviour: I have for example two rows in the datagrid. Row 1 is enabled (IsEnabled of the item is true), row 2 disabled (IsEnabled of the item is false). If I edit one of the integer values in row 1 and hit ENTER, the binding gets updated as expected. When I click into the very same Textbox again with the mouse pointer, the textblock underneath in the disabled row (2) gets activated (and highlighted with some grey color). If I want to edit the textblock in row 1 I have to click again somewhere else just to get away from the 'focused' textblock in row 2, and with a third click I could get back into the textblock I initially edited.

Is this a bug in the datagrid? How could I correct this, so that I could edit the textbox in row 1 again after clicking it again once?

Any ideas?

Thanks!

tabina
  • 1,095
  • 1
  • 14
  • 37

0 Answers0