开发者

Center current record in DataGridView

开发者 https://www.devze.com 2023-01-01 21:13 出处:网络
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 recor

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消