zoukankan      html  css  js  c++  java
  • 【DevExpress】老版TreeList和GridControl 中控件 MouseWheel事件禁用解决方法

    期望目标:TreeList和GridControl中禁用鼠标MouseWheel事件对控件值的更改。

    处理思路:在TreeList_ShownEditor事件中,增加对ActiveEditor的MouseWheel事件处理,禁用掉即可。

    遇到问题:老版DevExpress中对ActiveEditor.MouseWheel的Handle=true无效。

                  参加官方问题地址 http://www.devexpress.com/Support/Center/Question/Details/Q148215

    解决方法:

        既然无法禁用值的改变,那就从改变后恢复着手。代码如下:

        Private activeEditor As DevExpress.XtraEditors.BaseEdit = Nothing       '当前编辑控件
        Private isMouseWheelChanged As Boolean = False                          '是否为鼠标滚轮滚动改变
        Private oActiveEditorOldValue As Object = Nothing                       '初始值
    
        Private Sub TreeList_ShownEditor(ByVal sender As System.Object, ByVal e As System.EventArgs)
            activeEditor = m_tree.ActiveEditor
            oActiveEditorOldValue = activeEditor.EditValue
            AddHandler activeEditor.MouseWheel, AddressOf ActiveEditor_MouseWheel
            AddHandler activeEditor.EditValueChanging, AddressOf ActiveEditor_EditValueChanging
        End Sub
    Private Sub TreeList_HiddenEditor(ByVal sender As Object, ByVal e As System.EventArgs) If activeEditor IsNot Nothing Then isMouseWheelChanged = False oActiveEditorOldValue = Nothing End If End Sub
    ’出自 http://caryliu.cnblogs.com Private Sub ActiveEditor_MouseWheel(ByVal sender As System.Object, ByVal e As MouseEventArgs) isMouseWheelChanged = True If oActiveEditorOldValue IsNot Nothing Then Try RemoveHandler activeEditor.EditValueChanging, AddressOf ActiveEditor_EditValueChanging activeEditor.EditValue = oActiveEditorOldValue Catch ex As Exception Finally AddHandler activeEditor.EditValueChanging, AddressOf ActiveEditor_EditValueChanging End Try End If '转化为列表滚动 Dim scrollLines As Integer = SystemInformation.MouseWheelScrollLines If (scrollLines = -1) Then scrollLines = m_tree.ViewInfo.VisibleRowCount m_tree.TopVisibleNodeIndex += IIf(e.Delta > 0, -scrollLines, scrollLines) End Sub

    Private Sub ActiveEditor_EditValueChanging(ByVal sender As System.Object, ByVal e As DevExpress.XtraEditors.Controls.ChangingEventArgs) If isMouseWheelChanged Then e.Cancel = True Exit Sub End If oActiveEditorOldValue = e.OldValue End Sub
    作者:Cary Liu


    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,
    且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    【Java每日一题】20161202
    【Java每日一题】20161201
    【Java每日一题】20161130
    LeetCode刷题:Reverse Words in a String(翻转字符串中的单词)
    **公司实习生笔试总结
    C++ primer学习笔记_6_函数---函数定义、参数传递
    求职面试--复习笔记3
    求职面试--复习笔记2
    一道经典面试题,atoi函数的实现
    求职面试-算法复习系列
  • 原文地址:https://www.cnblogs.com/caryliu/p/2935373.html
Copyright © 2011-2022 走看看