我有一个DataGrid
和两个向上和向下按钮,以便用户可以在单击按钮时滚动浏览每个数据网格项目;向上或向下。我该怎么做呢?我已经尝试过SelectedIndex
,但似乎不适用于DataGrid
.
示例代码:
private void btnDownCheckedMedication_Click(object sender, RoutedEventArgs e)
{
if (MedicationCheckedInDatagrid.SelectedIndex > 0)
{
MedicationCheckedInDatagrid.SelectedIndex = MedicationCheckedInDatagrid.SelectedIndex - 1;
}
}
private void btnUpCheckedMedication_Click(object sender, RoutedEventArgs e)
{
MedicationCheckedInDatagrid.SelectedIndex = MedicationCheckedInDatagrid.SelectedIndex + 1;
}