日期:2014-05-19  浏览次数:21020 次

如何让DataGridView内数据为负数时候自动显示为红色
通过设置DataGridView.DataSource   为DateSet   显示数据库数据

怎样自动让数据为负数的时候显示为红色?

------解决方案--------------------
简单点的方法是...

在数据绑定后,用For循环遍历您要控制的列...

如果为负数,就改变其单元格的颜色...
------解决方案--------------------
CellFormating事件里搞定
------解决方案--------------------
private void view_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.Value == null)
return;
if (viewLeft.Columns[e.ColumnIndex].Name= "colname " && int.Parse(e.Value.ToString() <0)
{
e.CellStyle.BackColor = Color.Red;
}
}