Usuário com melhor resposta
Formatar Grid

Pergunta
-
Respostas
-
Carol,
Um exemplo em vb.net :
For Each Linha As DataGridViewRow In Me.TeuDataGridView.Rows
'Se a célula for do tipo Integer e não aceitar valores Null
If Linha.Cells(4).Value Is DBNull.Value Then
Linha.Cells(4).Value = False
End If
'Verifica se a célula do teu DataGridView tem o valor = "5"
If Linha.Cells(4).Value = "5" Then
Linha.Cells(4).Style.ForeColor = Color.Red
End If
Next
Para selecionar toda a linha, substituir :
Linha.Cells(4).Style.ForeColor = Color.Red
Por :
Linha.DefaultCellStyle.ForeColor = Color.Red
Utilizando o conversor, ficou assim em C# :
{
foreach (DataGridViewRow Linha in this.TeuDataGridView.Rows) {
if (object.ReferenceEquals(Linha.Cells(4).Value, DBNull.Value)) {
Linha.Cells(4).Value = false;
}
if (Linha.Cells(4).Value == "5") {
Linha.Cells(4).Style.ForeColor = Color.Red;
}
}
}
Abraços
Todas as Respostas
-
exemplo em C#
private void formataGrid()
{
for (int cont = 0; cont < DataGrid.Rows.Count; cont++)
{
criterio = DataGrid.Rows[cont].Cells[1].Value.ToString();
int criterio2=0;
criterio2 = int.Parse(criterio);if (criterio2 <= 5,0)
{
DataGrid.Rows[cont].Cells[0].Style.BackColor = Color.Tomato;
DataGrid.Rows[cont].Cells[1].Style.BackColor = Color.Tomato;
}
else
{
DataGrid.Rows[cont].Cells[0].Style.BackColor = Color.LimeGreen;
DataGrid.Rows[cont].Cells[1].Style.BackColor = Color.LimeGreen;
}
}
} -
Carol,
Um exemplo em vb.net :
For Each Linha As DataGridViewRow In Me.TeuDataGridView.Rows
'Se a célula for do tipo Integer e não aceitar valores Null
If Linha.Cells(4).Value Is DBNull.Value Then
Linha.Cells(4).Value = False
End If
'Verifica se a célula do teu DataGridView tem o valor = "5"
If Linha.Cells(4).Value = "5" Then
Linha.Cells(4).Style.ForeColor = Color.Red
End If
Next
Para selecionar toda a linha, substituir :
Linha.Cells(4).Style.ForeColor = Color.Red
Por :
Linha.DefaultCellStyle.ForeColor = Color.Red
Utilizando o conversor, ficou assim em C# :
{
foreach (DataGridViewRow Linha in this.TeuDataGridView.Rows) {
if (object.ReferenceEquals(Linha.Cells(4).Value, DBNull.Value)) {
Linha.Cells(4).Value = false;
}
if (Linha.Cells(4).Value == "5") {
Linha.Cells(4).Style.ForeColor = Color.Red;
}
}
}
Abraços