dv2020
Active member
- Joined
- Dec 18, 2020
- Messages
- 30
- Programming Experience
- 1-3
Hi All,
Trying to understand why formatting my datagridview is so slow with the code below.
Is there a more optimize way to perform the below?
I have found, when i remove the line below it speeds up a fair bit, I'm not to sure why this is occuring?
" row.Cells[speedcol].Style.Font = new Font(currentFont, currentFont.Style | FontStyle.Bold);"
Trying to understand why formatting my datagridview is so slow with the code below.
Is there a more optimize way to perform the below?
C#:
var currentFont = datagridProSpeedMap.DefaultCellStyle.Font;
string speedcol = "Speed";
decimal speedavg = 10;
decimal speedmax = 18;
for (int i = 0; i < datagridProSpeedMap.Rows.Count; i++)
{
DataGridViewRow row = datagridProSpeedMap.Rows[i];
if (Convert.ToDecimal(row.Cells[speedcol].FormattedValue) > speedavg && Convert.ToDecimal(row.Cells[speedcol].FormattedValue) != speedmax)
{
row.Cells[speedcol].Style.BackColor = cellnuetral;
row.Cells[speedcol].Style.ForeColor = Color.Black;
row.Cells[speedcol].Style.Font = new Font(currentFont, currentFont.Style | FontStyle.Bold);
}
}
I have found, when i remove the line below it speeds up a fair bit, I'm not to sure why this is occuring?
" row.Cells[speedcol].Style.Font = new Font(currentFont, currentFont.Style | FontStyle.Bold);"
Last edited: