Thursday, May 16, 2013

WPF DataGrid: Tabbing from cell to cell does not set focus on control



I tried many thigs which I found in different blog, but those did not work.
But then I found one simple and effective technique which worked like champ!!!

This need only 2 steps.

1. Add Style in your resource file:
    <!-- Cell Editing For DataGrid-->
    <Style x:Key="CellEditingStyle" TargetType="DataGridCell">
        <Setter Property="IsTabStop" Value="False" ></Setter>
    </Style>

2. Add this style in your data Grid:

                                <DataGridTemplateColumn Header="{DynamicResource grdLoadsPerMonths}" CellStyle="{StaticResource CellEditingStyle}">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBox Text="{Binding Path=LoadsPerMonth, UpdateSourceTrigger=LostFocus}"></TextBox>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                </DataGridTemplateColumn>


That is it. This has solved all the problem. No more work, no more class needs to be added.

Happy Codding!!!!!!!!!!!!!!!!!