ソリューション全体のすべての 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+Up で GO HOME の組み込み機能を終了し、Ctrl+Down でグリッドの GO END で終了します。onMouseDown では、ドラッグ アンド ドロップの一般的なコードを実行します。
このクラスが含まれているメイン プログラムのイベント _KeyDown および _MouseDown が決して発生しないことを除いて、これらはすべて実際に問題なく動作します。これらのコードをクラスから削除すると、メイン プログラムのイベントが期待どおりに発生します。
1)私が間違っていることと、メインプログラムで _KeyDown と _MouseDown をクラスの後に起動する方法。
2) DataGridView の組み込み機能 Ctrl+Click を取り除く方法は?