2014-02-28 88 views
0

我有一個DataGridView,右邊有一個usercontrol滾動條。在DataGridView內部滑動時,我可以在DataGridView中正常工作(從滑動中)獲取滾動事件。不幸的是,如果我在滑過DataGridControl(DataGridView之外)後立即滑過自定義滾動條,DataGridView仍會從滑動中獲取滾動事件。我想在DataGridView控件之外發生滑動(即想到的鼠標位置)時,在DataGridView中阻止這些滾動事件。相反,DataGridView之外的滾動條應該被點擊並滾動。我可以單獨管理自定義滾動條的滾動。想法讚賞。我沒有看到一個簡單的方法來取消滾動事件(在事件本身內)。感謝您的期待和任何幫助絕對讚賞。我在stackoverflow中看不到答案。對於梅德的答案(不能把在評論,因爲太長)Winforms:取消/防止在DataGridView外部滑動時滾動事件

我嘗試了,但得到的argumentoutofrange例外「索引超出範圍必須爲非負數且小於集合的大小。 \ r \ n參數名稱:索引「。在System.Collections.ArrayList.get_Item(的Int32指數) 在System.Windows.Forms.DataGridViewRowCollection.SharedRow(的Int32的rowIndex) 在System.Windows.Forms.DataGridView.ScrollRowsByHeight(的Int32高度) 在System.Windows.Forms的。 DataGridView.set_VerticalOffset(Int32 value) at System.Windows.Forms.DataGridView.DataGridViewVScrolled(Object sender,ScrollEventArgs se) at System.Windows.Forms.ScrollBar.OnScroll(ScrollEventArgs se) at System.Windows.Forms.ScrollBar。 DoScroll在System.Windows.Forms.Control.ControlNa(ScrollEventType型) 在System.Windows.Forms.ScrollBar.WmReflectScroll(消息&米) 在System.Windows.Forms.ScrollBar.WndProc(消息&米) tiveWindow.OnMessage(消息&米) 在System.Windows.Forms.Control.ControlNativeWindow.WndProc(消息&米) 在System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr的的HWND,MSG的Int32,IntPtr的WPARAM,IntPtr的LPARAM) 。想法和感謝?

回答

1

如果我正確理解你的問題,你可以嘗試處理的DataGridView的MouseLeave事件隱藏滾動條dataGridView1.ScrollBars = ScrollBars.None;,然後返回它們放回MouseEnter事件處理程序。

+0

查看上面編輯的問題,因爲不適合這個評論。謝謝! – Buck

+0

堆棧跟蹤很好,但異常引發的代碼在哪裏? – Dmitry

+0

對於源代碼,它表示mscorlib。在Application.Run調用後,異常本身會立即中斷。目標位於get_Item,Data位於System.Collections.ListDictionaryInternal。鍵和值的計數是0.我希望有幫助。如果別的東西能幫上忙,就讓我知道。謝謝 – Buck

相關問題