【问题标题】:How can I scroll to the last column of a DataGrid? [duplicate]如何滚动到 DataGrid 的最后一列? [复制]
【发布时间】:2011-12-06 21:20:24
【问题描述】:

可能重复:
Programatically bringing a Datagrid column into view (horizontal scroll)

我将 WPF 与 .NET 4 和 WPF Toolkit DataGrid 一起使用。 我有一个相当宽的数据网格,它的第一列被冻结,SelectionUnit - Cell。

我只需要在加载窗口后将此数据网格滚动到最后一列。 我试图将我的数据网格“放入”ScrollViewer - 但如果我使用它,数据网格的第一列将不再被冻结。 我尝试使用 datagrid 的 ScrollIntoView,但我没有为它选择项目,我无法选择一行来获取它(因为我的 SelectionUnit - 单元格)...

我可以做些什么来解决我的问题?谢谢!

【问题讨论】:

  • 我也看到了这篇文章...但是在加载数据网格的窗口 SelectedItem 后为空。如果我可以以编程方式选择第一行中的最后一个单元格...

标签: c# wpf datagrid


【解决方案1】:

为此,您只需在DataGrid 上使用函数ScrollIntoView(),第一行和最后一列如下:

object row = this.dataGrid1.Items[0]; //Grab the first row
DataGridColumn col = this.dataGrid1.Columns[this.dataGrid1.Columns.Count - 1]; //Grab the last column
this.dataGrid1.ScrollIntoView(row, col); //Set the view

【讨论】:

  • 谢谢!我知道有一个简单的解决方案))
猜你喜欢
  • 2015-07-09
  • 2011-07-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多