Ok, so I'm binding a DataGridView to a BindingSource in a background thread while a little, "Please Wait" model window keeps the user entertained. No problem.
However, I need to change some of the rows background colors based on the row's databounditem type. Like this:
for (int i = 0; i < dgItemMaster.Rows.Count; i++)
{
if (dgItemMaster.Rows[i].DataBoundItem.GetType().Name == "Package")
{
dgItemMaster.Rows[i].DefaultCellStyle.BackColor = Color.PowderBlue;
}
}
Programatically I can do this but it is enough rows that it will lock up the GUI while it is iterating the rows. I'm looking for ideas on the best way to deal with the situation.
This is what I'm doing now:
void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
dgItemMaster.DataSource = products;
dgItemMaster.BeginInvoke((Action)(() =>
{
for (int i = 0; i < dgItemMaster.Rows.Count; i++)
{
if (dgItemMaster.Rows[i].DataBoundItem.GetType().Name == "Package")
{
dgItemMaster.Rows[i].DefaultCellStyle.BackColor = Color.PowderBlue;
}
else if (dgItemMaster.Rows[i].DataBoundItem.GetType().Name == "PackageKit")
{
dgItemMaster.Rows[i].DefaultCellStyle.BackColor = Color.Pink;
}
}
}));
}