0
我需要繼承DataGridView以獲得某些功能,這是我的解決方案中所有DataGridView所需的功能。繼承DataGridView
爲我做這些示例代碼:
Imports System.ComponentModel
Public Class xDataGridView
Inherits DataGridView
Protected Overrides Sub onKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs)
If e.Control Then
If e.KeyCode = Keys.Up Or e.KeyCode = Keys.Down Then
e.Handled = True
End If
End If
End Sub
Protected Overrides Sub onMouseDown(ByVal e As MouseEventArgs)
' part of code for drag/drop
fromindex = Me.HitTest(e.X, e.Y).RowIndex
If fromindex > -1 Then
Dim dragSize As Size = SystemInformation.DragSize
dragrect = New Rectangle(New Point(CInt(e.X - (dragSize.Width/2)), CInt(e.Y - (dragSize.Height/2))), dragSize)
Else
dragrect = Rectangle.Empty
End If
End Sub
用的onkeydown我終止內建功能爲Ctrl +向上HOME和用Ctrl +下井去格的結束。 隨着onMouseDown我做拖放通用代碼。
所有這些實際上工作正常,除了我的事件_KeyDown和_MouseDown在這個類包括的主程序永遠不會被解僱! 如果我從類中刪除這些代碼,那麼主程序中的事件按預期發射。
1)我做錯了什麼,以及如何讓主程序中的_KeyDown和_MouseDown在課後被觸發。
2)如何擺脫DataGridView的內置功能Ctrl + Click?
真的!如預期那樣工作,謝謝。對第二個問題有幫助嗎? –