Center current record in DataGridView
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开发者_JAVA百科 like it to be in the middle. Would this be possible/simpler in WPF?
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;
精彩评论