• 【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


    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,
    且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    js 每个月有多少天算法
    js 树的操作
    画线
    程序员如何防止脑疲劳
    汉字求出拼音缩写
    datagird 多行外于编辑状态
    overflow: hidden 失效
    CSS 相对/绝对(relative/absolute)定位系列(三)
    display:inlineblock在Chrome与FF下导致的间隙
    css ul li 的使用及浏览器兼容问题
  • 原文地址:https://www.cnblogs.com/caryliu/p/2935373.html
Copyright © 2020-2023  润新知