问题描述
我正在从 datagridview 继承的控件中实现一些拖放功能.基本上,我从 DGV 中的某处拖动一行并将其放在其他地方,重新排列行.不过我遇到了一个问题.如果 DGV 太大以至于出现滚动条,我如何在用户处于拖放中间时让 DGV 向上或向下滚动?
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?
我知道如何获取当前鼠标位置以及如何获取 dgv 矩形等的位置.所以,我可以很容易地找出我是在矩形的上半部分还是下半部分......我只需要一种以编程方式滚动 dgv 的方法.如果我不必不断更改所选单元格来执行此操作,我会更喜欢.
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.
有什么建议吗?
谢谢
以撒
推荐答案
好吧,因为这是一个 datagridview... 抱歉问题中的winforms"...但我可以这样做...向上滚动或向下一排.
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.
向上滚动:
this.FirstDisplayedScrollingRowIndex = this.FirstDisplayedScrollingRowIndex - 1
向下滚动:
this.FirstDisplayedScrollingRowIndex = this.FirstDisplayedScrollingRowIndex + 1;
你必须确保检查数字没有越界.
You've gotta make sure to check that the numbers don't go out of bounds though.
这篇关于如何以编程方式滚动 winforms datagridview 控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!