如何将焦点设置到WPF工具包的DataGrid的特定的细胞 [英] how to set focus to particular cell of WPF toolkit datagrid

查看:229
本文介绍了如何将焦点设置到WPF工具包的DataGrid的特定的细胞的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用提供的DataGrid控件,其OpenStock,说明等。在此我DataGrid中已设置OpenStock列编辑和休息是不可编辑一起显示产品列表WPF工具包。我现在想,当我的这个Windows加载,我想设置键盘焦点OpenStock列的第一个单元格,如果可能,在编辑模式。我搜索这2天,终于在这里发帖。

I am using WPF toolkit provided DataGrid control to display product list along with its OpenStock, Description etc. In this DataGrid i have set OpenStock column to editable and rest are non-editable. What i want now when my this windows loads, I want to set keyboard focus to first cell of OpenStock column and if possible in edit mode. I searched this for 2 days and finally posting here.

任何帮助或代码示例将是有益的。

any help or code sample would be helpful.

<my:DataGrid AutoGenerateColumns="False" ItemsSource="{Binding}" Margin="2,2,2,55" 
x:Name="dataGrid1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="White"    
AlternatingRowBackground="AliceBlue" AlternationCount="2" SelectionMode="Single" 
SelectionUnit="Cell" BorderThickness="0" IsTabStop="True">
        <my:DataGrid.Resources>
            <Style x:Key="errorStyle" TargetType="{x:Type TextBox}">
                <Setter Property="Padding" Value="-2"/>
                <Style.Triggers>
                    <Trigger Property="Validation.HasError" Value="True">
                        <Setter Property="Background" Value="Yellow"/>
                        <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self},
                                Path=(Validation.Errors)[0].ErrorContent}"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </my:DataGrid.Resources>
        <my:DataGrid.Columns>
            <my:DataGridTextColumn Width="60" FocusManager.IsFocusScope="False" Binding="{Binding Path=pCode}" Header="Code" IsReadOnly="True" />
            <my:DataGridTextColumn Width="150" Binding="{Binding pName}" Header="Description"  IsReadOnly="True" />
            <my:DataGridTextColumn Width="120" Binding="{Binding CloseStock}" Header="Closing Stock"  IsReadOnly="True" />
            <my:DataGridTextColumn  Width="100" Binding="{Binding OpenStock, ValidatesOnExceptions=True}" Header="Open Stock"
                                   EditingElementStyle="{StaticResource errorStyle}"/>
            <my:DataGridTextColumn Width="150" Binding="{Binding YrlyOpenStock}" Header="Yearly Opening"  IsReadOnly="True" />

        </my:DataGrid.Columns>
    </my:DataGrid>       



非常感谢........

thanks alot........

推荐答案

您需要将当前单元格设置为你想要编辑的一个,然后调用的BeginEdit 在加载处理程序:

You need to set the current cell to the one you want edited and then call BeginEdit in your Loaded handler:

dataGrid1.CurrentCell = new DataGridCellInfo(
    dataGrid1.Items[0], dataGrid1.Columns[3]);
dataGrid1.BeginEdit();

如果你给你的DataGridTextColumn XAML中,你可以使用该名称,而不是列[3] 。

If you give your DataGridTextColumn a name in XAML you can use that name rather than Columns[3].

这篇关于如何将焦点设置到WPF工具包的DataGrid的特定的细胞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆