开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜