【问题标题】:How to focus on a specific cell when adding a new row to Datagrid?向 Datagrid 添加新行时如何关注特定单元格?
【发布时间】:2023-03-22 03:29:02
【问题描述】:

当使用 Silverlight/WPF Datagrid 并向现有集合添加新行时,如何跳转到特定单元格的编辑模式以提示用户该字段需要立即填写?

非常感谢,

【问题讨论】:

标签: c# .net wpf silverlight datagrid


【解决方案1】:

在 Silverlight 4 中是:

dg.SelectedItem = data;
dg.CurrentColumn = dg.Columns[1]; // You have to use this line instead
dg.Focus();
dg.BeginEdit();

【讨论】:

    【解决方案2】:

    这就是我如何让它在 SL 5 RC 中工作。

    dg.ItemsSource.Add(data);
    dg.SelectedItem = data;                  //set SelectedItem to the new object
    dg.ScrollIntoView(data, dg.Columns[0]);  //scroll row into view, for long lists, setting it to start with the first column
    dg.Focus();                              //required in my case because contextmenu click was not setting focus back to datagrid
    dg.BeginEdit();                          //this starts the edit, this works because we set SelectedItem above
    

    希望这会有所帮助。

    【讨论】:

    • 在 SL 4 中,我必须添加“dg.CurrentColumn = dg.Columns[1];”在设置焦点之前。否则,它工作得很好,这很有帮助。
    猜你喜欢
    • 2017-07-25
    • 2020-06-21
    • 2019-11-20
    • 2018-04-25
    • 2012-04-07
    • 1970-01-01
    • 2021-05-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多