最終形 ----------------------------------------------------------------------------------------------------------------------------------------------------- Private Sub DataGridView1_CellPainting(ByVal sender As Object, ByVal e As DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting On Error Resume Next '列ヘッダーかどうか調べる If e.ColumnIndex < 0 And e.RowIndex >= 0 Then 'セルを描画する e.Paint(e.ClipBounds, DataGridViewPaintParts.All)
'行番号を描画する範囲を決定する 'e.AdvancedBorderStyleやe.CellStyle.Paddingは無視しています Dim indexRect As Rectangle = e.CellBounds indexRect.Inflate(-2, -2) '行番号を描画する TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), e.CellStyle.Font, indexRect, e.CellStyle.ForeColor, TextFormatFlags.Right Or TextFormatFlags.VerticalCenter) '描画が完了したことを知らせる e.Handled = True End If
DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGray End Sub
Private Sub DGVDataAdd(workStr As List(Of String())) DataGridView1.Rows.Clear() On Error GoTo ErrorNext Dim ws As List(Of String()) = workStr Dim x As Integer = 0 For Each work In ws DataGridView1.Rows.Add(work) DataGridView1(LogData.LogKinds, x).Style.BackColor = LogKind_ColorChange(work) DataGridView1(LogData.Operation, x).Style.ForeColor = Operation_ColorChange(work) x += 1 Next ErrorNext: DataGridView1.Refresh() End Sub