WPF Datagrid专注于新行 [英] WPF Datagrid focus on new row

查看:92
本文介绍了WPF Datagrid专注于新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有datagrid,带有addnew按钮和删除按钮列。

当我点击添加新按钮时,焦点应该出现在新行上。

我该怎么办?





现在我添加了两个活动

I have datagrid with addnew button and delete button columns.
when i click on add new button the focus should come on the new row.
What should i do?


Now i have added two events

private void DataGrid_CurrentCellChanged(object sender, EventArgs e)
        {
            DataGrid.BeginEdit();
        }

private void DataGrid_PreparingCellForEdit(object sender, DataGridPreparingCellForEditEventArgs e)
        {
                UIElement inputElement;
                inputElement = DataGridHelper.GetVisualChild<TextBox>(e.EditingElement);
                if (inputElement != null)
                {
                    Keyboard.Focus(inputElement);
                }
        }









但是现在我必须点击两次AddNewButton来获取新行或删除我点击两次删除按钮。



解决这个问题我该怎么办? br />
请帮帮我!





But Now i have to click twice the AddNewButton for a new row to come or for deleting i have click twice the delete button.

To Solve this what should i do?
Please help me!

推荐答案

你可能会因为试图找到聚焦而感到困惑,但这个概念不适用细胞。 焦点始终表示键盘焦点,仅适用于整个控件。



对于单元格或行,您需要应用选择。只需选择其中一个单元格:

http ://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.currentcell.aspx [ ^ ]。



结果取决于选择模式。



-SA
You are confused probably because you are trying to find how to "focus", but this notion is not applicable to cells. "Focus" always mean "keyboard focus" and is only applicable to the whole control.

For a cell or a row, you need to apply "selection". Just select one of the cells:
http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.currentcell.aspx[^].

The result of it depends on selection mode.

—SA


这篇关于WPF Datagrid专注于新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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