ถ้าทั้ง Rows
Code:
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
int iRow = e.RowIndex;
DataGridViewRow r = dataGridView1.Rows[iRow];
double cellValue = Convert.ToDouble (r.Cells[5].Value); //UnitPrice
if (cellValue <= 20)
{
r.DefaultCellStyle.BackColor = Color.Yellow ;
r.DefaultCellStyle.ForeColor = Color.Red;
}
}
ถ้าเฉพาะ cells
Code:
...
..
.
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
//UnitPrice :=> e.ColumnIndex == 5
if ( ( e.Value != null) && (e.ColumnIndex == 5))
{
if (Convert.ToInt32(e.Value) <= 20)
{
e.CellStyle.BackColor = Color.Yellow;
e.CellStyle.ForeColor = Color.Red;
}
}
}
This comment has been removed by the author.
ReplyDelete