在代码中,我在列表详细信息屏幕中向Light Switch网格添加新记录。如何将焦点(放置光标)设置在底行的第三列(刚添加的记录)?
public partial class JobsBudgetListDetail
{
static DataGrid budgetGrid;
partial void JobBudgetsAddNew_Execute()
{
int jobID = Jobs.SelectedItem.JobID;
int maxLineNo = 0;
if (Jobs.SelectedItem.JobBudgets.Count() > 0)
maxLineNo = this.DataWorkspace.ContractorData.JobBudgetsByDescLineNoForGivenJobID(jobID).FirstOrDefault().BudgetLineNo;
JobBudget newBudget = this.DataWorkspace.ContractorData.JobBudgets.AddNew();
newBudget.BudgetDate = this.propertyBudgetDate;
newBudget.BudgetLineNo = maxLineNo + 10;
newBudget.Job = Jobs.SelectedItem;
Microsoft.LightSwitch.Threading.Dispatchers.Main.BeginInvoke(() =>
{
// next line selects the row just added
budgetGrid.SelectedIndex = JobBudgets.Count - 1;
// now, how set focus to column 3 on this row?
});
}
答案 0 :(得分:1)
jberger是对的,但我不确定语法。在查看一些Silverlight网站后,我发现这有效:
budgetGrid.CurrentColumn = budgetGrid.Columns[2];
回想起来非常简单!