16,717
社区成员
发帖
与我相关
我的任务
分享
Private Sub DataGridView1_CellMouseEnter(ByVal sender As Object, _
ByVal e As DataGridViewCellEventArgs) _
Handles DataGridView1.CellMouseEnter
'ヘッダー以外のセル
If e.ColumnIndex >= 0 And e.RowIndex >= 0 Then
Dim dgv As DataGridView = CType(sender, DataGridView)
'セルスタイルを変更する
dgv(e.ColumnIndex, e.RowIndex).Style.BackColor = Color.Red
dgv(e.ColumnIndex, e.RowIndex).Style.SelectionBackColor = Color.Red
End If
End Sub
'DataGridView1のCellMouseLeaveイベントハンドラ
Private Sub DataGridView1_CellMouseLeave(ByVal sender As Object, _
ByVal e As DataGridViewCellEventArgs) _
Handles DataGridView1.CellMouseLeave
'ヘッダー以外のセル
If e.ColumnIndex >= 0 And e.RowIndex >= 0 Then
Dim dgv As DataGridView = CType(sender, DataGridView)
'セルスタイルを元に戻す
'セルスタイルを削除するなら、nullを設定してもよい
dgv(e.ColumnIndex, e.RowIndex).Style.BackColor = Color.Empty
dgv(e.ColumnIndex, e.RowIndex).Style.SelectionBackColor = Color.Empty
End If
End Sub
Private Sub DataGridView1_CellMouseLeave(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellMouseLeave
Dim i As Integer
For i = 0 To DataGridView1.RowCount - 1
DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.White
Next
End Sub
Private Sub DataGridView1_CellMouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseMove
Dim i As Integer
For i = 0 To DataGridView1.RowCount - 1
DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.Gainsboro
Next
End Sub