C
C#13mo ago
yumo

Painting Cells | Excel Import to DGV

I've been trying for the past hours making this work but im confused or the code is confusing itself, so i have some excels that i want to import and to verify them i have some rules like :
All and only the NORMs in column 2 that have the TxtObra number in column 0 are all red except for those containing "MNO", "EXT", "PNO", "ELE", "EPA", "PIL" which are white. Now, without counting the NORMs in column 2, color all those that do not contain the TxtObra in column 0 in orange, otherwise color in green.
this is the code, am i blind i'm tired i don't think i can figure this out in the moment , maybe tomorrow i can look better at this but either way i would like to make this today :/
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 0 && dataGridView1.Rows[e.RowIndex].Cells[0].Value != null)
{
string txtObra = "TxtObra"; // Substitua "TxtObra" pelo valor real que você está verificando
string cellValue = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
string cell2Value = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();

if (cellValue.Contains(txtObra) && !cell2Value.Contains("MNO") && !cell2Value.Contains("EXT") && !cell2Value.Contains("PNO") && !cell2Value.Contains("ELE") && !cell2Value.Contains("EPA") && !cell2Value.Contains("PIL"))
{
e.CellStyle.BackColor = Color.White;
}
else if (cellValue.Contains(txtObra))
{
e.CellStyle.BackColor = Color.Red;
}
else if (!cell2Value.Contains("NORM"))
{
e.CellStyle.BackColor = Color.Orange;
}
else
{
e.CellStyle.BackColor = Color.Green;
}
}
}
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 0 && dataGridView1.Rows[e.RowIndex].Cells[0].Value != null)
{
string txtObra = "TxtObra"; // Substitua "TxtObra" pelo valor real que você está verificando
string cellValue = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
string cell2Value = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();

if (cellValue.Contains(txtObra) && !cell2Value.Contains("MNO") && !cell2Value.Contains("EXT") && !cell2Value.Contains("PNO") && !cell2Value.Contains("ELE") && !cell2Value.Contains("EPA") && !cell2Value.Contains("PIL"))
{
e.CellStyle.BackColor = Color.White;
}
else if (cellValue.Contains(txtObra))
{
e.CellStyle.BackColor = Color.Red;
}
else if (!cell2Value.Contains("NORM"))
{
e.CellStyle.BackColor = Color.Orange;
}
else
{
e.CellStyle.BackColor = Color.Green;
}
}
}
Also i left a screenshot here for a better visual in what's going on , ping me if need me i will be online for more half an hour
No description
1 Reply
yumo
yumoOP13mo ago
im so tired i placed this post in the #code-review by mistake...
Want results from more Discord servers?
Add your server