I am using the below syntax to color code sales persons data. The issue that I have is that the datagridview returns roughly 12,000 rows so the coloring syntax takes some extensive time to execute.
Is there a way to optimize this code?
private void datagridview1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
foreach (DataGridViewRow row in datagridview1.Rows)
{
if (row.Cells["Jake"].Value == System.DBNull.Value && row.Cells["Jones"].Value == System.DBNull.Value && row.Cells["Lati"].Value == System.DBNull.Value && row.Cells["Venitia"].Value == System.DBNull.Value)
{
row.DefaultCellStyle.BackColor = Color.Red;
}
}
}
private void PopulateIT()
{
datagridview1.Visible = true;
lblNoData.Visible = false;
string connString = @"Connection String";
string query = @"SELECT * from tempdata";
SqlConnection conn = new SqlConnection(connString);
SqlCommand cmd = new SqlCommand(query, conn);
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(formattedDT);
conn.Close();
da.Dispose();
datagridview1.DataSource = formattedDT;
datagridview1.AutoResizeColumns();
}
DataGridView datagridview1
in the first place? \$\endgroup\$