Answer the question
In order to leave comments, you need to log in
How to highlight a table row when pressing the mouse button, etc.?
Hello. The question is easy. How to highlight a row of the DataGrid table when pressing the mouse button in a WPF project programmatically (code).
Answer the question
In order to leave comments, you need to log in
Add a MouseDown handler :
The handler code is something like this:
private void dataGrid_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.RightButton == MouseButtonState.Pressed)
{
var row = DataGridRow.GetRowContainingElement(e.OriginalSource as FrameworkElement);
if (row != null)
{
// dataGrid.SelectedIndex = row.GetIndex();
dataGrid.SelectedItem = row;
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question