突出显示数据网格中的第一行 [英] Highlight the first row in the data grid
本文介绍了突出显示数据网格中的第一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的WPF窗口中,我有一个数据网格.加载窗口时,我想突出显示数据网格中的第一行.如果是这样的话,我应该能够使用箭头键在数据网格中滚动而不用在网格上停留.
In my WPF window I have a datagrid. I want to highlight the first row in the data grid when loading the window. if so I should be able to scroll through rows in the data grid using arrow keys without clikcing on the grid.
推荐答案
将DataGrid的SelectedIndex属性设置为0
Set SelectedIndex property of DataGrid as 0.
DataGrid.SelectedIndex = 0
但是在设置SelectedIndex之前,您应该确保DataGrid ItemsSource中至少有1行/项目.因此,您可以在if条件中使用上述代码.
But before setting SelectedIndex you should make sure that there is atleast 1 row/item in DataGrid ItemsSource. So you can have above code in if condition.
这篇关于突出显示数据网格中的第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文