如何定位一个DataGridView到特定行(使得所选择的行是在底部)? [英] How do I position a DataGridView to a specific row (so that the selected row is at the bottom)?

查看:1318
本文介绍了如何定位一个DataGridView到特定行(使得所选择的行是在底部)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于类似的这个问题,我也有它一个DataGridView的应用程序。我想位置的行,使得一个特定的行位于列表的可见部分的底部。

As a question similar to this question, I also have an application with a DataGridView on it. I would like to position the rows such that a specific row is at the bottom of the visible part of the list.

这是响应于按钮点击可移动的由一个排下来。我要维护我向前行的选择(我已经有这部分工作)。如果有大量的行中,所选行可能移动至可见区域的下方。欲向下滚动,直到它在可见光区域的底部。

This is in response to a button click that moves a row down by one. I want to maintain the selection on the row I'm moving (I already have this part working). If there are lots of rows, the selected row might move below the visible area. I want to scroll down until it's at the bottom of the visible area.

有没有出现是一个LastDisplayedScrollingRowIndex同伴FirstDisplayedScrollingRowIndex

There does not appear to be a LastDisplayedScrollingRowIndex companion to FirstDisplayedScrollingRowIndex.

任何想法?谢谢你。

推荐答案

随着我的猜测,我想我需要使用FirstDisplayedScrollingRowIndex和行DataGridView的可视计算的数量新FirstDisplayedScrollingRowIndex。也许我只是需要找出什么NumberOfVisibleRows属性被称为?

As my own guess, I think I need to use FirstDisplayedScrollingRowIndex and the number of rows visible in the DataGridView to calculate the new FirstDisplayedScrollingRowIndex. Maybe I just need to find out what the NumberOfVisibleRows property is called?

发现了它。 DisplayedRowCount:

Found it. DisplayedRowCount:

if (dataGridView.FirstDisplayedScrollingRowIndex + dataGridView.DisplayedRowCount(false) <= selectedRowIndex)
{
    dataGridView.FirstDisplayedScrollingRowIndex =
        selectedRowIndex - dataGridView.DisplayedRowCount(false) + 1;
}

代码测试,在我自己的项目。

Code tested and working in my own project.

这篇关于如何定位一个DataGridView到特定行(使得所选择的行是在底部)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆