如何以编程方式滚动一个winforms datagridview控件? [英] How do I programmatically scroll a winforms datagridview control?

查看:101
本文介绍了如何以编程方式滚动一个winforms datagridview控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个从datagridview继承的控件中实现一些拖放功能。基本上我在DGV的某个地方拖了一排,并将其放在别的地方,重新排列行。我遇到了一个问题。如果DGV太大,以至于有一个滚动条,那么当用户在拖动画面的中间时,如何让DGV向上或向下滚动?



我知道如何获取当前的鼠标位置,并获取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屋!

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