7

I have a datagrid with template columns in WPF. Couple of columns in the grid are readonly, others on focus become editable (instead of labels, textboxes, checkboxes and such appear).

What I would like to achieve is that the readonly columns are skipped when I am tabbing through the grid's columns.

Anyone know how to achieve this?

Thanks! Vladan


Nope, not working :(

Here is the complete cell...tried it with KeyboardNavigation.IsTabStop and IsTabStop alone...didn't work

<DataGridTemplateColumn Header="{x:Static local:MainWindowResources.gasNameLabel}" Width="*" MinWidth="150" IsReadOnly="True">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <ContentControl Content="{Binding Path=Name}" ContentTemplate="{StaticResource DataGridTextBoxView}" />
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
    <DataGridTemplateColumn.CellStyle>
        <Style TargetType="{x:Type DataGridCell}">
            <Style.Triggers>
                <Trigger Property="IsReadOnly" Value="true">
                    <Setter Property="KeyboardNavigation.IsTabStop" Value="False"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </DataGridTemplateColumn.CellStyle>
</DataGridTemplateColumn>
Tim Post
  • 33,371
  • 15
  • 110
  • 174
Vladan Strigo
  • 551
  • 1
  • 7
  • 19
  • Have you tried the `Enabled` property or `Focusable` property. I've never tried either of those on the `DataGrid` but it's worth a shot. – CodingGorilla Sep 27 '11 at 21:10

1 Answers1

14

Something like this would work:

<DataGrid.Resources>
    <Style TargetType="DataGridCell">
        <Style.Triggers>
            <Trigger Property="IsReadOnly" Value="True">
                <Setter Property="IsTabStop" Value="False"/>
            </Trigger>
        </Style.Triggers>
    </Style>
</DataGrid.Resources>
H.B.
  • 166,899
  • 29
  • 327
  • 400