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
2010-05-27 20:12:31
It works. Thanks. Although you've probably meant grid.SelectedRows[0].Index;
Max
2010-05-30 20:41:34