如何以编程方式滚动一个winforms datagridview控件? [英] How do I programmatically scroll a winforms datagridview control?
问题描述
我知道如何获取当前的鼠标位置,并获取dgv矩形的位置等。所以,我可以很容易地找出我是否在矩形的顶部或底部的一半...我只需要一种以编程方式滚动dgv的方法。如果我不需要继续更改选定的单元格,我更愿意这样做。
任何建议?
谢谢
Isaac
一个datagridview ...对不起,'winforms'在问题...但我可以这样做..向上或向下滚动一行。
向上滚动:
this.FirstDisplayedScrollingRowIndex = this.FirstDisplayedScrollingRowIndex - 1
向下滚动:
this.FirstDisplayedScrollingRowIndex = this.FirstDisplayedScrollingRowIndex + 1;
你必须确保检查数字不会超出界限。 / p>
I'm implementing some drag drop features in one my controls inheriting from a datagridview. Basically I'm dragging a row from somewhere in the DGV and dropping it somewhere else, reordering the rows. I've run into a problem though. If the DGV is too large such that there's a scrollbar, how can I have the DGV scroll up or down while the user is in the middle of a dragdrop?
I know how to get the current mouse position and also get the position of the dgv rectangle and such. So, I can easily find out if i'm in the top or bottom half of the rectangle... I just need a way to programmatically scroll the dgv. I'd prefer if I don't have to keep changing the selected cell to do this.
Any suggestions?
Thanks
Isaac
Well, since this is a datagridview... Sorry for the 'winforms' in the question... but I could just do this.. scrolling up or down one row.
Scroll up:
this.FirstDisplayedScrollingRowIndex = this.FirstDisplayedScrollingRowIndex - 1
Scroll Down:
this.FirstDisplayedScrollingRowIndex = this.FirstDisplayedScrollingRowIndex + 1;
You've gotta make sure to check that the numbers don't go out of bounds though.
这篇关于如何以编程方式滚动一个winforms datagridview控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!