0
votes

I have a WPF DataGrid.

When a user press the tab key i dont want to get focus on 1st column and also 3rd column so when i reach a row i should be in the second column and when i press tab key again and reach 3 column it sholud move to 4th column.

How can i do this in WPF DataGrid

2

2 Answers

5
votes

The TabStopIndex value is what indicates which field should receive focus next when the Tab key is pressed. Additionally, you can disable a control's TabStop entirely by setting it through the KeyboardNavigation.IsTabStop attached property.

XAML:

<DataGrid ItemsSource="{Binding}" AutoGenerateColumns="False">
        <DataGrid.Resources>
            <Style x:Key="NoTabStopStyle" TargetType="{x:Type DataGridCell}">
                <Setter Property="KeyboardNavigation.IsTabStop" Value="False"/>
            </Style>
        </DataGrid.Resources>
        <DataGrid.Columns>
            <DataGridTextColumn Binding="{Binding Path=FirstColumn}" CellStyle="{StaticResource NoTabStopStyle}"/>
            <DataGridTextColumn Binding="{Binding Path=SecondColumn}"/>
            <DataGridTextColumn Binding="{Binding Path=ThirdColumn}" CellStyle="{StaticResource NoTabStopStyle}"/>
        </DataGrid.Columns>
    </DataGrid>
0
votes

You can disable those columns:

<Window.Resources>
    <Style x:Key="NotSelectableColumStyle" TargetType="{x:Type DataGridCell}">
        <Setter Property="IsEnabled" Value="False"/>
    </Style>
</Window.Resources>

<Grid Name="LayoutRoot">
     <DataGrid ItemsSource="{Binding}" AutoGenerateColumns="False">
        <DataGrid.Columns>
            <DataGridTextColumn   Binding="{Binding Path=Age}" />
            <!--<Disable this column>-->    
            <DataGridTextColumn   CellStyle="{StaticResource NotSelectableColumStyle}" Binding="{Binding Path=Name}" />
            <DataGridTextColumn  Binding="{Binding Path=Address}" />
        </DataGrid.Columns>
    </DataGrid>
 </Grid>