私はDataGridView
に問題があります。私はCellFormattingメソッドを使用してその内容に基づいて行の色を変更しています。これは、ほとんどの場合、DGVの最初の行が真を返すまでうまくいくように見えます。この場合、DGVのすべての行は赤で表示されます。C#DataGridView行の色付け
は、ここに私のコードです:
private void MyData_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
DataGridViewRow theRow = MyData.Rows[e.RowIndex];
if (theRow.Cells[4].Value.ToString() == "1")
{
ChangeRowColor(theRow, Color.PaleVioletRed);
}
}
private void ChangeRowColor(DataGridViewRow r, Color c)
{
r.DefaultCellStyle.BackColor = c;
}
編集:ソリューション:
private void MyData_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
DataGridViewRow theRow = MyData.Rows[e.RowIndex];
if ((int)theRow.Cells[4].Value == 1)
{
e.CellStyle.BackColor = Color.PaleVioletRed;
}
}
私のためのフォーマットのおかげで、私はnewbです – Krisisonfire
else else節の後に 'else {ChangeRowColor(theRow、Color.White);}'を追加すると便利ですか? – Pikoh
サンプルデータを提供できますか? – Berkay