[英]Mark a cell in my datagrid when the program starts
我可以使用以下代码轻松地以编程方式标记我的数据网格中的单元格:
DataGrid1.ScrollIntoView(DataGrid1.Items[Rowindex]);
DataGrid1.Focus();
DataGrid1.CurrentCell = new DataGridCellInfo(DataGrid1.Items[Rowindex], DataGrid1.Columns[Columnindex]);
DataGrid1.SelectedCells.Clear();
DataGrid1.SelectedCells.Add(DataGrid1.CurrentCell);
但是,这仅在我启动我的程序一次并且数据网格已完全加载后才有效。 但是,我尝试在第一次启动时进行滚动和突出显示。 我的方法调用如下所示:
public DataBaseWindow()
{
InitializeComponent();
// Here i do some other Stuff.
jump_to_cell();
}
public void jump_to_cell()
{
DataGrid1.ScrollIntoView(DataGrid1.Items[Rowindex]);
DataGrid1.Focus();
DataGrid1.CurrentCell = new DataGridCellInfo(DataGrid1.Items[Rowindex], DataGrid1.Columns[Columnindex]);
DataGrid1.SelectedCells.Clear();
DataGrid1.SelectedCells.Add(DataGrid1.CurrentCell);
}
当我以编程方式 select 一个单元格时,选择被突出显示。 但是,不是我第一次启动该程序时。 然后不幸的是没有任何反应。
编辑:我找到了解决问题的方法。 如果我只是在 .Show 方法之后设置方法调用,它就可以工作。 =>
DatabaseWindow DB1 = new DatabaseWindow();
DB1.Owner = this;
DB1.Show();
DB1.jump_to_cell();
您还可以使用 WindowLoaded 或 ContentRendered 事件。
<Window ...
ContentRendered="Window_ContentRendered">
private void Window_ContentRendered(object sender, RoutedEventArgs e)
{
//do something
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.