掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
DataGridViewの色に関して (ID:103321)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
開発環境:VIsual Basic 2008 あるデータをDataGridViewに表示させていますが、その際に、同じ区分のデータで あれば、グループ化(色を変える)したいと考え、以下の記述をあるHPから検索し、プログラムしました。 やりたい事はこれに近かった為、これを加工しましたが、グループ化した際の色が "緑"となってしまっている為、この色をなんとか変更できないか?と考えています。 どこを変更すれば良いか教えて下さい。 よろしくお願いします。 《記述内容》 'デフォルトのセルスタイル Private defaultCellStyle As DataGridViewCellStyle 'グループ化された一番上の行のセルスタイル Private groupCellStyle As DataGridViewCellStyle 'フォームのLoadイベントハンドラ Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load 'セルスタイルを設定する Me.defaultCellStyle = New DataGridViewCellStyle() Me.groupCellStyle = New DataGridViewCellStyle() Me.groupCellStyle.ForeColor = Color.White Me.groupCellStyle.BackColor = Color.DarkGreen Me.groupCellStyle.SelectionBackColor = Color.DarkBlue End Sub 'CellFormattingイベントハンドラ Private Sub DataGridView1_CellFormatting(ByVal sender As Object, _ ByVal e As DataGridViewCellFormattingEventArgs) _ Handles DataGridView1.CellFormatting Dim dgv As DataGridView = CType(sender, DataGridView) 'セルが1列目で、ヘッダーではなく、新しい行でもないとき If e.ColumnIndex = 0 AndAlso e.RowIndex >= 0 AndAlso _ e.RowIndex <> dgv.NewRowIndex Then If e.RowIndex = 0 OrElse _ Not dgv(e.ColumnIndex, e.RowIndex - 1).Value.Equals(e.Value) Then '1行目か、上のセルと違う値の時は、背景色を変更する dgv.Rows(e.RowIndex).DefaultCellStyle = Me.groupCellStyle Else dgv.Rows(e.RowIndex).DefaultCellStyle = Me.defaultCellStyle e.Value = "" e.FormattingApplied = True End If End If End Sub
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.