掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
DataGridViewのRaadOnly背景色を変えない (ID:145902)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
回答ありがとうございます、早速試し思い通りの結果が確認できました。 下記にコードを貼り付けました。 --追加質問-- 氏名セルをクリックするとカーソルがなくなります、個人番号 にカーソルを残す事はできないでしょうか? 質問にきりがなくて申し訳ありません。 Public Class Form1 Private dgv As DataGridView Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load 'dgv = New DataGridView() 'dgv.Dock = DockStyle.Fill 'Controls.Add(dgv) DataGridView1.AllowUserToAddRows = False DataGridView1.ColumnCount = 2 DataGridView1.RowCount = 100 '全体の色 With DataGridView1.DefaultCellStyle .ForeColor = Color.DarkGreen .BackColor = Color.Lavender .SelectionForeColor = .ForeColor .SelectionBackColor = .BackColor End With '奇数行の色 With DataGridView1.AlternatingRowsDefaultCellStyle .BackColor = Color.White .SelectionBackColor = .BackColor End With DataGridView1.Columns(1).ReadOnly = True DataGridView1.Focus() DataGridView1.CurrentCell = DataGridView1(1, 0) DataGridView1.BeginEdit(True) End Sub ''' <summary>セルがフォーカスされた時の処理です。</summary> Private Sub DataGridView1_CellEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEnter ' セルの背景色を変更します。 If e.ColumnIndex >= 0 And e.RowIndex >= 0 Then DataGridView1.Item(e.ColumnIndex, e.RowIndex).Style.BackColor = Color.Yellow DataGridView1.BeginEdit(True) End If End Sub ''' <summary>セルがフォーカスを失う時の処理です。</summary> Private Sub DataGridView1_CellLeve(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellLeave ' セルの背景色を変更します。 If e.ColumnIndex >= 0 And e.RowIndex >= 0 Then DataGridView1.Item(e.ColumnIndex, e.RowIndex).Style.BackColor = Color.Empty DataGridView1.EndEdit() End If End Sub Private Sub DataGridView1_CellValidated(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValidated Dim currentCell As DataGridViewCell = DataGridView1.Item(e.ColumnIndex, e.RowIndex) If currentCell Is Nothing Then Return End If If Not e.ColumnIndex = 0 Then Return Dim no As Integer = DataGridView1.Item(e.ColumnIndex, e.RowIndex).Value Select Case no Case "1" DataGridView1.Item(e.ColumnIndex + 1, e.RowIndex).Value = "鈴木" Case "2" DataGridView1.Item(e.ColumnIndex + 1, e.RowIndex).Value = "佐藤" End Select End Sub End Class
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.