views:

23

answers:

1

When programmatically changing the current record in the DataGridView is it possible to make it in such way that this record would be centered (vertically) in the grid? When I change the current record it is shown either as the top row or as the bottom row. I'd like it to be in the middle. Would this be possible/simpler in WPF?

+1  A: 

I haven't tried this, but if all rows are the same height, I think you could set the first visible row to the index of your selected row minus half the number of visible rows.

First, select the row you want centered, then:

int x = grid.SelectedRows[0].DisplayIndex;

grid.FirstDisplayedScrollingRowIndex = x - grid.DisplayedRowCount() / 2;
Charles
It works. Thanks. Although you've probably meant grid.SelectedRows[0].Index;
Max