将DataGridView设置为DataSource后,以编程方式将其滚动到最后一行 [英] Programmatically scroll DataGridView to last row after setting it's DataSource

查看:70
本文介绍了将DataGridView设置为DataSource后,以编程方式将其滚动到最后一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将DatGridView绑定到BindingSource,并且在将其设置为DataSource之后尝试将其滚动到底部.

I've got DatGridView bound to BindingSource and I'm trying to scroll it to the bottom after setting it's DataSource.

绑定源的MoveLast()使最后一行处于选中状态,但不会向下滚动.我尝试设置FirstDisplayedScrollingRowIndex,但是它会引发InvalidOperationException,并显示一条消息没有空间可用于显示行".

Binding source's MoveLast() make's last row selected but it doesn't scroll down. I've tried to set FirstDisplayedScrollingRowIndex, but it throws InvalidOperationException with a message "No room is available to display rows".

当我调用MoveLast或稍后更改FirstDisplayedScrollingRowIndex时,例如在按钮单击事件中,它工作良好,但是我想打开一个新窗口,将DataGridView的最后一行设置为当前并且对用户可见.

When I call MoveLast or change FirstDisplayedScrollingRowIndex later, for example in button click event, it works well, but I want to open a new window with DataGridView's last row set as current and visible to user.

推荐答案

听起来像在构造函数中调用FirstDisplayedScrollingRowIndex吗?尝试在表单的load事件中执行此操作.不得已时,您可以在Activate事件中进行设置并设置一个标志,以便仅在表单绘制完成后才执行一次.

Sounds like your calling FirstDisplayedScrollingRowIndex in the constructor? Try doing it in the load event of the form. Last resort you can do it in the Activate event and set a flag so it only executes once after the form is done drawing itself.

这篇关于将DataGridView设置为DataSource后,以编程方式将其滚动到最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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