您的位置:首页 > 其它

【DevExpress】老版TreeList和GridControl 中控件 MouseWheel事件禁用解决方法

2013-02-27 16:26 621 查看
期望目标: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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: