|  | ■No87476 (あらら さん) に返信 > datagridview上でCtrl+Aキーを押すと
 > 4行目から一番下までの行だけが選択するように
 
 こういうことで良いのかな。
 
 先頭行を「0行目」と数えているのか、「1行目」と数えているのかが分からなかったので、
 ひとまず、全選択直後に先頭 3 行だけ選択解除するようにしてみました。
 
 
 Partial Public Class Form1
 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
 DataGridView1.DataSource = Nothing
 DataGridView1.AllowUserToAddRows = False
 DataGridView1.Columns.Clear()
 DataGridView1.RowCount = 5
 DataGridView1.ColumnCount = 5
 End Sub
 
 Private Sub DataGridView1_KeyDown(sender As Object, e As KeyEventArgs) Handles DataGridView1.KeyDown
 If e.KeyData = (Keys.Control Or Keys.A) Then
 e.SuppressKeyPress = True
 Dim currentCell = DataGridView1.CurrentCell
 If DataGridView1.RowCount > 3 Then
 DataGridView1.SelectAll()
 For rowIndex = 0 To 2
 DataGridView1.Rows(rowIndex).Selected = False
 Next
 Else
 DataGridView1.ClearSelection()
 End If
 DataGridView1.CurrentCell = currentCell
 e.Handled = True
 End If
 End Sub
 End Class
 
 |