您的位置:首页 > 编程语言 > C#

C# DataGridView改变行颜色

2015-08-05 23:08 295 查看
例子一:

private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)

{

{

if(e.RowIndex < dataGridView1.Rows.Count -1)

{

DataGridViewRow dgrSingle = dataGridView1.Rows[e.RowIndex];

try

{

if(dgrSingle.Cells["列名"].Value.ToString().Contains("比较值"))

{

dgrSingle.DefaultCellStyle.ForeColor = Color.Red;

}

}

catch(Exception ex)

{

MessageBox.Show(ex.Message);

}

}

}

例子二:

private void dataGridView1_CellPainting(object sender,DataGridViewCellPaintingEventArgs e)

{

if(e.RowIndex == 2 && e.ColumnIndex> =0)

{

using(SolidBrush brush = new SolidBrush(Color.Red))

{

e.Graphics.FillRectangle(brush,e.CellBounds);

e.Handled = true;

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: