积极答复者
datagridview的问题

问题
答案
-
可以考虑使用DataGrid的Paint事件中,遍历记录,找出满足条件的行,通过设置DataGridViewCell.Style的属性来实现。
We are the staff of stars- 已标记为答案 BoberSongModerator 2010年7月23日 5:48
-
你可以在绑定DATAGRIDVIEW后,遍历DATAGRIDVIEW,根据每行单元格的值进行判断
for (int i = 0; i < dataGridView1.Rows.Count; i++) { if (dataGridView1.Rows[i].Cells["Title"].Value!=null) { if (dataGridView1.Rows[i].Cells["Title"].Value.ToString() == "1") { dataGridView1.Rows[i].Cells["Title"].Style.ForeColor = Color.Blue;//改变单元格背景色 //dataGridView1.Rows[i].DefaultCellStyle.BackColor= Color.Blue;改变行背景色 } else { dataGridView1.Rows[i].Cells["Title"].Style.ForeColor = Color.Red; } } }
http://blog.csdn.net/zx13525079024- 已标记为答案 BoberSongModerator 2010年7月23日 5:48
全部回复
-
可以考虑使用DataGrid的Paint事件中,遍历记录,找出满足条件的行,通过设置DataGridViewCell.Style的属性来实现。
We are the staff of stars- 已标记为答案 BoberSongModerator 2010年7月23日 5:48
-
你可以在绑定DATAGRIDVIEW后,遍历DATAGRIDVIEW,根据每行单元格的值进行判断
for (int i = 0; i < dataGridView1.Rows.Count; i++) { if (dataGridView1.Rows[i].Cells["Title"].Value!=null) { if (dataGridView1.Rows[i].Cells["Title"].Value.ToString() == "1") { dataGridView1.Rows[i].Cells["Title"].Style.ForeColor = Color.Blue;//改变单元格背景色 //dataGridView1.Rows[i].DefaultCellStyle.BackColor= Color.Blue;改变行背景色 } else { dataGridView1.Rows[i].Cells["Title"].Style.ForeColor = Color.Red; } } }
http://blog.csdn.net/zx13525079024- 已标记为答案 BoberSongModerator 2010年7月23日 5:48
-
我觉得可以有几种方法处理这个问题。看每个人的爱好。
我喜欢的处理方式是在数据库中,你的存储过程,或者是select语句。
可以根据你的考勤状态字段来决定颜色。比如:
select case when state=1 then '<font color=''red''>'+username+'</font>'
when state=2 then '<font color=''blue''>'+username+'</font>'
else username end username from table这样颜色不就出来了,
还有种方法,就是在前台cs文件中,gridview的行绑定事件中,根据字段state值,来决定单元格的颜色。