I will show you how to navigate records by clicking Next
and Previous
, below is my code for you to implement it:
Part1: Add two Buttons
in xaml:
<Button Name="btnPre" Width="120" Height="30" Content="Previous" Click="btn_Click"></Button>
<Button Name="btnNext" Width="120" Height="30" Content="Next" Click="btn_Click"></Button>
Part 2: The code for btn_Click
private void btn_Click(object sender, RoutedEventArgs e)
{
int selectedIndex = 0;
if(dataGrid.SelectedIndex > 0)
{
selectedIndex = dataGrid.SelectedIndex;
}
string strContent = (sender as Button).Content.ToString();
if (strContent == "Previous" && selectedIndex>0)
{
dataGrid.SelectedIndex = selectedIndex-1;
DataGridRow row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(selectedIndex - 1);
row.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
}
else if (strContent == "Next" && selectedIndex <dataGrid.Items.Count-1)
{
dataGrid.SelectedIndex = selectedIndex +1;
DataGridRow row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(selectedIndex + 1);
row.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
}
}
By the way, could you give me more description for your controls to change values correspondingly to the datagrid highlighter
? How do you want to change the value?
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.