我的C#.NET應用程序中的一種形式具有多個DataGridView,它們實現拖放以移動行。拖放大部分工作正常,但我一直很難得到DataGridViews到AutoScroll - 當一行被拖動到框的頂部或底部附近時,以此方向滾動它。如何在拖放過程中自動滾動DataGridView
到目前爲止,我已嘗試實施this解決方案的一個版本。我有一個ScrollingGridView類從實現所述定時器的DataGridView繼承,並根據調試器,定時器被適當地射擊,但定時器代碼:
const int WM_VSCROLL = 277;
private static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
private void ScrollingGridViewTimerTick(object sender, EventArgs e)
{
SendMessage(Handle, WM_VSCROLL, (IntPtr)scrollDirectionInt, IntPtr.Zero);
}
不這樣做,據我可以告訴什麼,可能是因爲我在窗體中有多個DataGridViews。我也嘗試修改AutoScrollOffset屬性,但那也沒有做任何事。 DataGridView和ScrollBar類的調查似乎沒有建議任何其他命令或功能,實際上將使DataGridView滾動。任何人都可以幫助我一個實際上會滾動DataGridView的函數,或者其他解決問題的方法嗎?
好像我們正在研究同樣的問題;一個能夠拖放行的datagridview – 2010-04-02 17:45:53
@Mason:對不起,請參閱我的新工作解決方案的答案。 – 2010-04-05 14:36:18
謝謝,夥計們。看起來這兩個解決方案的工作,但我標記this.FirstDisplayedScrollingRowIndex ++之一被接受,因爲它似乎更容易維護,而不是拉入一個DLL併發送一個記錄不好的Windows消息。但是,如果有人想以任何理由這樣做,那麼傳遞VerticalScrollBar.Handle作爲第四個參數是它的工作原理。 – Mason 2010-04-05 16:33:38