0
I wonder if there is any way to color datagridview line without using a loop.
I have a minimum stock and when available is below the minimum would like to paint the red line.
I did it that way, but it got too slow.
for (int i = 0; i < dgvEstoque_pecas.RowCount - 1; i++)
{
int disponivel = 0, minimo = 0;
if (dgvEstoque_pecas.Rows[i].Cells["disponivel"].Value.ToString() != "")
{
disponivel = Convert.ToInt32(dgvEstoque_pecas.Rows[i].Cells[disponivel].Value.ToString());
}
else
{
disponivel = 0;
}
if (dgvEstoque_pecas.Rows[i].Cells["minimo"].Value.ToString() != "")
{
minimo = Convert.ToInt32(dgvEstoque_pecas.Rows[i].Cells["minimo"].Value.ToString());
}
else
{
minimo = 0;
}
if (disponivel < minimo)
dgvEstoque_pecas.Rows[i].DefaultCellStyle.BackColor = Color.Red;
}
Search by Rowdatabound, it is a Web or Desktop project?
– Leandro Angelo
It’s a Windows Forms, Desktop project.
– Antonio Gomes
So you don’t have Rowdatabound, you can try for Cellformatting
– Leandro Angelo
try something like this,
DataGridViewCell cell = new DataGridViewTextBoxCell();

 cell.Style.BackColor = Color.Wheat;
this can also help ************https://msdn.microsoft.com/pt-br/library/system.windows.datagridviewcellstyle(v=vs.110). aspx– Doan Casotti