dataGridView1如何设置整行的颜色 我把列表显示在dataGridView1中现在想把条件符合的行的颜色设置为灰色怎么弄??? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 DataGridView1_CellFormatting中e.CellStyle.BackColor this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Red;http://blog.csdn.net/ConExpress/archive/2008/11/20/3338481.aspx DataGridView.Row[i].DefaultCellStyle.BackColor 参考DataGridView指定单元格颜色设定光标下的单元格颜色自动变换 [C#]private void DataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e){ if (e.ColumnIndex >= 0 && e.RowIndex >= 0) { DataGridView dgv = (DataGridView)sender; dgv[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.Red; dgv[e.ColumnIndex, e.RowIndex].Style.SelectionBackColor = Color.Red; }}private void DataGridView1_CellMouseLeave(object sender, DataGridViewCellEventArgs e){ if (e.ColumnIndex >= 0 && e.RowIndex >= 0) { DataGridView dgv = (DataGridView)sender; dgv[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.Empty; dgv[e.ColumnIndex, e.RowIndex].Style.SelectionBackColor = Color.Empty; }} private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e) { if (e.RowIndex >= dataGridView1.Rows.Count -1 || e.RowIndex<0) return; DataGridViewRow dgr = dataGridView1.Rows[e.RowIndex]; try { if (dgr.Cells[ "列名"].Value.ToString() == "比较的值") { dgr.DefaultCellStyle.BackColor = Color.Gray; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } http://www.cnblogs.com/peterzb/archive/2009/05/29/1491891.html 我把问题在补充一下啊 我从后台数据库中返回DataTable付给dataGridView1。dataGridView1里面每行有个字段Ddate(日期)我想判断日期小于当前时间的就把这行的颜色换为灰色??? DataGridView根据单元格值设定单元格样式单元格负数情况下显示黄色,0的情况下显示红色 [C#]private void DataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e){ DataGridView dgv = (DataGridView)sender; if (dgv.Columns[e.ColumnIndex].Name == "Column1" && e.Value is int) { int val = (int)e.Value; if (val < 0) { e.CellStyle.BackColor = Color.Yellow; } else if (val == 0) { e.CellStyle.BackColor = Color.Red; } }}参考这个吧!对比日期就行了 在VS中调用WebService正常,在IIS中没反应 WPF 自定义列问题,求高手解答 求助求助 关于datatable 操作Excel的问题 请教:如何在网页上将变量的值赋值到客户端应用程序的一个变量中去。 100分!求VS2005简体中文正式版下载地址。我现在用的是企业版。另:正式版和企业版有什么区别?怎么区分正式版和企业版?正式版用起来比 急求 C# 编程词典(完整版) 一个问题,请大家帮忙:) 咋在C井里面运行其他的程序?? C# 文本框问题 怎么才能知道tfs上每个shelveset里面包含哪些文件?
中e.CellStyle.BackColor
this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Red;
http://blog.csdn.net/ConExpress/archive/2008/11/20/3338481.aspx
DataGridView指定单元格颜色设定
光标下的单元格颜色自动变换
[C#]
private void DataGridView1_CellMouseEnter(object sender,
DataGridViewCellEventArgs e)
{
if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
{
DataGridView dgv = (DataGridView)sender;
dgv[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.Red;
dgv[e.ColumnIndex, e.RowIndex].Style.SelectionBackColor = Color.Red;
}
}private void DataGridView1_CellMouseLeave(object sender,
DataGridViewCellEventArgs e)
{
if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
{
DataGridView dgv = (DataGridView)sender;
dgv[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.Empty;
dgv[e.ColumnIndex, e.RowIndex].Style.SelectionBackColor = Color.Empty;
}
}
{
if (e.RowIndex >= dataGridView1.Rows.Count -1 || e.RowIndex<0)
return;
DataGridViewRow dgr = dataGridView1.Rows[e.RowIndex];
try
{
if (dgr.Cells[ "列名"].Value.ToString() == "比较的值")
{
dgr.DefaultCellStyle.BackColor = Color.Gray;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
} }
DataGridView根据单元格值设定单元格样式
单元格负数情况下显示黄色,0的情况下显示红色
[C#]
private void DataGridView1_CellFormatting(object sender,
DataGridViewCellFormattingEventArgs e)
{
DataGridView dgv = (DataGridView)sender; if (dgv.Columns[e.ColumnIndex].Name == "Column1" && e.Value is int)
{
int val = (int)e.Value;
if (val < 0)
{
e.CellStyle.BackColor = Color.Yellow;
}
else if (val == 0)
{
e.CellStyle.BackColor = Color.Red;
}
}
}参考这个吧!对比日期就行了