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

Hou*_*man 2 .net c# silverlight wpf datagrid

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

非常感谢,

Far*_*res 7

这就是我能够在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
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助.

  • 在SL 4中,我不得不添加"dg.CurrentColumn = dg.Columns [1];" 在设置焦点之前.在其他方面,它运作良好,这有很大帮助. (2认同)