をロードするフォームがありますDataGridView。CellPaintingセルの値に基づいて行に色を付けるイベントを作成しました。CellPaintingの行を繰り返し処理してペイントするのにDatagridview時間がかかりすぎたので、これはより効率的です。
問題点)
- この
CellPaintingイベントは、フォームの読み込みには対応していません。つまり、スクロールまたはクリックするまですべての行が非表示になり、セルの値に基づいて正しく描画されます。 - 私が気付いたもう 1 つのことは、列ヘッダーが欠落していることです。他の問題は
DataGridView、スクロール バーで行を下にスクロールするCellPaintingと、再度呼び出され、行の色が再描画されるまで数秒待たなければならないことです。これは、特に何千行もある場合に非常に煩わしく、スクロールするたびにスクロールが遅延します。
これらの問題はすべてなくなり、メソッドDatagridViewを削除すると列ヘッダーと行がすべて表示されるCellPaintingため、明らかに問題があります。以下は私のスニペットです。助けていただければ幸いです。
private void timeLineDataGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
//only bold and/or color the rows that are false
if ((Boolean)timeLineDataGridView.Rows[e.RowIndex].Cells[12].Value == false)
{
//get timestamp and go ahead and bold it
DateTime eventTime = DateTime.Parse(timeLineDataGridView.Rows[e.RowIndex].Cells["TIMESTAMP"].Value.ToString());
timeLineDataGridView.Rows[e.RowIndex].DefaultCellStyle.Font = this.boldFont;
if (eventTime < this.delay_warn_time3)
{
timeLineDataGridView.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red;
}
else if (eventTime < this.delay_warn_time2)
{
timeLineDataGridView.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Orange;
}
else if (eventTime < this.delay_warn_time1)
{
timeLineDataGridView.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Yellow;
}
}
}