V
V
Vitaly Pitalenko2018-02-22 08:56:11
WPF
Vitaly Pitalenko, 2018-02-22 08:56:11

How to highlight the first row of a DataGrid programmatically in C#?

There is a TextBlock in which the search string is entered, the finished result of the matches is displayed in the DataGrid.
How, when pressing the Enter key in a TextBlock, select to transfer the focus to the DataGrid and select the first element of the table?

if (DataGrid.Items.Count > 0)
{
DataGrid.Focus();
DataGrid.SelectedItem = DataGrid.Items[0];
}
Такой код не прокатил.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
d-stream, 2018-02-23
@d-stream

should be enough:

DataGrid.SelectedItem = DataGrid.Items[0];
DataGrid.ScrollIntoView(DataGrid.Items[0]);

In general: https://social.technet.microsoft.com/wiki/contents...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question