In my case I want to scroll to the top row in certain circumstances. The code that works isn't elegant as it will fire events that I really don't want. To get around that I use a flag that I set before updating the grid, then reset after. Here's the code:
_fillingSearchGrid = true;
SearchResultsGrid.DataSource = results;
if (SearchResultsGrid.Rows.Count > 0)
{
SearchResultsGrid.CurrentRow = SearchResultsGrid.ChildRows[0];
SearchResultsGrid.CurrentRow = null;
}
_fillingSearchGrid = false;
Is there a better way to do this?
_fillingSearchGrid = true;
SearchResultsGrid.DataSource = results;
if (SearchResultsGrid.Rows.Count > 0)
{
SearchResultsGrid.CurrentRow = SearchResultsGrid.ChildRows[0];
SearchResultsGrid.CurrentRow = null;
}
_fillingSearchGrid = false;