【问题标题】:Winforms: Cancel/Prevent Scrolling Event When Swipe Outside of DataGridViewWinforms:在 DataGridView 之外滑动时取消/防止滚动事件
【发布时间】:2014-02-28 14:35:34
【问题描述】:

我有一个 DataGridView,它的右侧有一个用户控件滚动条。在 DataGridView 内滑动时,我在 DataGridView 中得到滚动事件,它工作正常(来自滑动)。不幸的是,如果我在滑过 DataGridControl(DataGridView 之外)后立即滑过自定义滚动条,DataGridView 仍然会从滑动中获取滚动事件。当滑动(即思考鼠标位置)发生在 DataGridView 控件之外时,我想阻止 DataGridView 中的这些滚动事件。相反,应该单击并滚动 DataGridView 外部的滚动条。我可以单独管理自定义滚动条的滚动。想法赞赏。我看不到取消滚动事件的简单方法(在事件本身内)。感谢您的关注,任何帮助都非常感谢。我在stackoverflow中没有看到答案。

对于德米特里的回答(由于太久无法发表评论):我试过了,但得到一个参数超出范围异常“索引超出范围。必须是非负数且小于大小集合的名称。\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 值) 在 System.Windows.Forms.DataGridView.DataGridViewVScrolled(对象发送者,ScrollEventArgs se) 在 System.Windows.Forms.ScrollBar.OnScroll(ScrollEventArgs se) 在 System.Windows.Forms.ScrollBar.DoScroll(ScrollEventType 类型) 在 System.Windows.Forms.ScrollBar.WmReflectScroll(消息和 m) 在 System.Windows.Forms.ScrollBar.WndProc(消息和 m) 在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(消息& m) 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(消息和 m) 在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)。想法和感谢?

【问题讨论】:

    标签: c# winforms events scroll touch


    【解决方案1】:

    如果我正确理解您的问题,您可以尝试处理 DataGridView 的 MouseLeave 事件以隐藏滚动条 dataGridView1.ScrollBars = ScrollBars.None;,然后将它们返回到 MouseEnter 事件处理程序中。

    【讨论】:

    • 请参阅上面已编辑的问题,因为此评论不适合。谢谢!
    • 堆栈跟踪很好,但是引发异常的代码在哪里?
    • 对于源它表示 mscorlib。异常本身在 Application.Run 调用后立即中断。目标站点位于 get_Item,数据位于 System.Collections.ListDictionaryInternal。键和值的计数为 0。我希望这会有所帮助。如果有其他帮助,请告诉我。谢谢
    • 我认为您在自定义滚动条的 Scroll 事件处理程序中有错误。您似乎正在尝试滚动到索引超出范围的行。请验证或提供其源代码。
    • 作为猜测,可能在将行添加到DataGridView 之前引发了异常。如果为真,您应该在Scroll 事件处理程序中检查这一点。
    猜你喜欢
    • 1970-01-01
    • 2020-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-20
    相关资源
    最近更新 更多