簡體   English   中英

Winforms:在DataGridView外部滑動時取消/阻止滾動事件

[英]Winforms: Cancel/Prevent Scrolling Event When Swipe Outside of DataGridView

我有一個DataGridView,其右側帶有一個用戶控件滾動條。 在DataGridView內滑動時,我在DataGridView中獲得了滾動事件,該滾動事件工作正常(通過滑動)。 不幸的是,如果我在滑過DataGridControl(在DataGridView之外)后立即滑過自定義滾動條,則DataGridView仍然會從滑動中獲取滾動事件。 我想防止在DataGridView控件之外進行滑動(例如,思考鼠標的位置)時在DataGridView中發生這些滾動事件。 而是應單擊並滾動DataGridView外部的滾動條。 我可以從自定義滾動條單獨管理滾動。 想法表示贊賞。 我看不到取消滾動事件的簡單方法(在事件本身內)。 感謝您的協助,我們非常感謝您的幫助。 在stackoverflow中沒有看到答案。

對於Dmitry的答案(由於時間太長,無法在注釋中進行評論):我嘗試了此操作,但收到了參數outofrange異常“索引超出范圍。必須為非負數,並且小於集合的大小。\\ r \\ n參數名稱:指數”。 在System.Windows.Forms.DataGridViewRowCollection.SharedRow(Int32 rowIndex)在System.Windows.Forms.DataGridView.ScrollRowsByHeight(Int32高度)在System.Windows.Forms.DataGridView.set_VerticalOffset在System.Collections.ArrayList.get_Item(Int32索引)在System.Windows.Forms.ScrollBar.OnScroll(ScrollEventArgs se)的System.Windows.Forms.DataGridView.DataGridViewVScrolled(Object sender,ScrollEventArgs se)的(Int32值) System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&m)的System.Windows.Forms.ScrollBar.WndProc(Message&m)的System.Windows.Forms.ScrollBar.WmReflectScroll(Message&m) System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)的Control.ControlNativeWindow.WndProc(Message&m)。 想法和感謝?

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM