画面イメージ
フォーカスを得たときに背景色を変更する
VB
Private Sub DataGridView1_CellEnter(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellEnter
DataGridView1(e.ColumnIndex, e.RowIndex).Style.SelectionBackColor = Color.Blue
End Sub
フォーカスを失ったときに背景色を元に戻す
VB
Private Sub DataGridView1_CellLeave(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellLeave
DataGridView1(e.ColumnIndex, e.RowIndex).Style.SelectionBackColor = Color.Empty
End Sub
動作確認用コード
VB
Public G_dtStock As New DataTable
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
With G_dtStock
.Columns.Add("ProductID", GetType(String))
.Columns.Add("Stock", GetType(String))
.Rows.Add("C1", "10")
.Rows.Add("C2", "150")
.Rows.Add("C3", "-90")
.Rows.Add("C4", "30")
.Rows.Add("C5", "120")
End With
With DataGridView1
.DataSource = G_dtStock
.AllowUserToAddRows = False
End With
End Sub
コメント