[英]How to focus on a specific cell when adding a new row to Datagrid?
使用 Silverlight/WPF Datagrid 並向現有集合添加新行時,如何跳轉到特定單元格的編輯模式以提示用戶需要立即填寫此字段?
非常感謝,
這就是我如何讓它在 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
希望這可以幫助。
在 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.