简体   繁体   English

向 Datagrid 添加新行时如何关注特定单元格?

[英]How to focus on a specific cell when adding a new row to Datagrid?

When using Silverlight/WPF Datagrid and you add a new row to the existing collection, how can I jump into a specific cell's edit mode in order to hint to the user that this field needs to be filled out right away?使用 Silverlight/WPF Datagrid 并向现有集合添加新行时,如何跳转到特定单元格的编辑模式以提示用户需要立即填写此字段?

Many Thanks,非常感谢,

This is how I was able to make it work in SL 5 RC.这就是我如何让它在 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

Hope this helps.希望这可以帮助。

In Silverlight 4 it is:在 Silverlight 4 中它是:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM