*自由区/.NET Tipsの器/DaraGridViewの使用方法/実用 [#x99ec421]
下記のファイル名(コントロール継承ファイルに追加)
ファイル名
DataGridVeiwEx.Designer.vb

    <System.Security.Permissions.UIPermission( _
        System.Security.Permissions.SecurityAction.Demand, _
        Window:=System.Security.Permissions.UIPermissionWindow.AllWindows)> _
    Protected Overrides Function ProcessDialogKey( _
            ByVal keyData As Keys) As Boolean

        If (keyData And Keys.KeyCode) = Keys.Tab OrElse (keyData And Keys.KeyCode) = Keys.Enter Then
            '***現在の行
            Dim col As Integer
            Dim row As Integer = Me.CurrentCell.RowIndex
            If (keyData And Keys.Shift) = Keys.Shift Then
                col = Me.CurrentCell.ColumnIndex - 1
            Else
                col = Me.CurrentCell.ColumnIndex + 1
            End If
            While 0 <= col AndAlso col < Me.Columns.Count AndAlso Me.Columns(col).ReadOnly
                If (keyData And Keys.Shift) = Keys.Shift Then
                    col -= 1
                Else
                    col += 1
                End If
            End While
            If col < 0 Then
                row -= 1
            ElseIf Me.ColumnCount <= col Then
                row += 1
            End If
            If 0 <= row AndAlso row < Me.RowCount Then
                If col < 0 Then
                    Return MyBase.ProcessDialogKey(keyData)
                ElseIf 0 <= col AndAlso col < Me.Columns.Count Then
                    '***現在の行
                    Me.CurrentCell = Me.Rows(Me.CurrentCell.RowIndex).Cells(col)
                Else
                    '***次行
                    col = 0
                    While col < Me.Columns.Count AndAlso Me.Columns(col).ReadOnly
                        col += 1
                    End While
                    If row < Me.RowCount AndAlso col < Me.ColumnCount Then
                        Me.CurrentCell = Me.Rows(row).Cells(col)
                    End If
                End If
                Return True
            ElseIf Me.RowCount <= col Then
                'Me.SelectNextControl(Me, True, True, True, True)
            End If
        End If
        Return MyBase.ProcessDialogKey(keyData)
    End Function

    <System.Security.Permissions.SecurityPermission( _
        System.Security.Permissions.SecurityAction.Demand, _
        Flags:=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)> _
    Protected Overrides Function ProcessDataGridViewKey( _
            ByVal e As KeyEventArgs) As Boolean
        If (e.KeyData And Keys.KeyCode) = Keys.Tab OrElse (e.KeyData And Keys.KeyCode) = Keys.Enter Then
            Dim col As Integer
            Dim row As Integer = Me.CurrentCell.RowIndex
            If e.Shift Then
                'シフトTABのときの動き
                col = Me.CurrentCell.ColumnIndex - 1
                While 0 <= col AndAlso Me.Columns(col).ReadOnly
                    col -= 1
                End While
                If col < 0 Then
                    row -= 1
                    If 0 < row Then
                        Return Me.FindForm().SelectNextControl(Me, False, False, False, True)
                    ElseIf 0 <= row AndAlso row < Me.RowCount Then
                        '***前行
                        col = Me.Columns.Count - 1
                        While 0 <= col AndAlso Me.Rows(row).Cells(col).ReadOnly
                            col -= 1
                        End While

                        Me.CurrentCell = Me.Rows(row).Cells(col)
                        Return True
                    End If
                Else
                    '***現在の行
                    Me.CurrentCell = Me.Rows(Me.CurrentCell.RowIndex).Cells(col)
                    Return True
                End If
            Else
                'TABのときの動き
                col = Me.CurrentCell.ColumnIndex + 1
                While col < Me.Columns.Count AndAlso Me.Columns(col).ReadOnly
                    col += 1
                End While
                If Me.ColumnCount <= col Then
                    row += 1
                    '***次行
                    col = 0
                    While col < Me.Columns.Count AndAlso Me.Columns(col).ReadOnly
                        col += 1
                    End While
                    If row < Me.RowCount Then
                        Me.CurrentCell = Me.Rows(row).Cells(col)
                        Return True
                    Else
                        e.Handled = False
                        Me.FindForm().SelectNextControl(Me.FindForm().ActiveControl, True, True, True, True)
                        Return True
                    End If
                Else
                    If 0 <= col AndAlso col < Me.Columns.Count Then
                        '***現在の行
                        Me.CurrentCell = Me.Rows(row).Cells(col)
                        Return True
                    End If
                End If
            End If
        End If
        Return MyBase.ProcessDataGridViewKey(e)
    End Function
では、よりいいコントロールボックスを作成してください。

//これより下は編集しないでください
#pageinfo(,2013-12-15 (日) 21:29:39,,2013-12-15 (日) 21:29:39,)

[ トップ ]   [ 編集 | 差分 | バックアップ | 添付 | 複製 | 名前変更 | リロード ]   [ 新規 | 子ページ作成 | 一覧 | 単語検索 | 最終更新 | ヘルプ ]