V
V
Vladislav Sofienko2016-11-07 08:18:25
.NET
Vladislav Sofienko, 2016-11-07 08:18:25

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

1 answer(s)
A
Alexey Nemiro, 2016-11-07
@sofvlad

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 question

Ask a Question

731 491 924 answers to any question