Colorare righe DataGridView






Colorare row DataGridView1


Dim Rs As New ADODB.Recordset
Rs = New ADODB.Recordset
Dim sql As String = "SELECT Tabelle.NomeTabella, Campi.Campo, Campi.Tipo, Campi.lungo, Campi.PrimaryKey, Campi.Ricerca FROM Tabelle INNER JOIN Campi ON Tabelle.id = Campi.IdTabella WHERE (((Tabelle.NomeTabella)=" & Chr(34) & Combo1.Text & Chr(34) & ")) ORDER BY Tabelle.NomeTabella, Campi.id;"
Rs.Open(sql, DBStruttura, 3, 3)
DataGridView1.Rows.Clear()

With DataGridView1.ColumnHeadersDefaultCellStyle
.BackColor = Color.Navy
.ForeColor = Color.White
.Font = New Font("Ariel", 12, FontStyle.Bold) 'Font(DataGridView1.Font, FontStyle.Bold)
End With

Dim Colore As System.Drawing.Color
Colore = Color.PaleGoldenrod
Do While Not Rs.EOF
Dim n As Integer = DataGridView1.Rows.Add()

If Colore = Color.PaleGoldenrod Then
Colore = Color.White
Else
Colore = Color.PaleGoldenrod
End If

DataGridView1.Rows(n).DefaultCellStyle.BackColor = Colore

DataGridView1.Rows.Item(n).Cells(0).Value = Rs.Fields("campo").Value
'DataGridView1.Rows.Item(n).DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomLeft

DataGridView1.Rows.Item(n).Cells(1).Value = Rs.Fields("Tipo").Value
DataGridView1.Rows.Item(n).Cells(2).Value = Rs.Fields("Lungo").Value
DataGridView1.Rows.Item(n).Cells(3).Value = Rs.Fields("Ricerca").Value
DataGridView1.Rows.Item(n).DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopCenter
Rs.MoveNext()

Loop

Rs.Close()










( colorarerighedatagridview.html )- by Paolo Puglisi - Modifica del 17/12/2023