首页 新闻 会员 周边

winform中datagridview单元格设置

0
悬赏园豆:10 [已关闭问题] 关闭于 2011-01-25 16:35

怎么在winform中对某一列的单元格中符合条件的字高亮显示,比如:姓名:小名,在这一列中只要是姓名:小名就要高亮显示

问题补充: 不是设置整个单元格的,而是设置单元格中符合条件的文字的颜色并非单元格中的全部颜色
辛思利的主页 辛思利 | 初学一级 | 园豆:108
提问于:2011-01-25 10:49
< >
分享
所有回答(2)
0

取到当前单元格,然后设置背景色。

清海扬波 | 园豆:825 (小虾三级) | 2011-01-25 11:08
private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e) { if (e.RowIndex >= (dataGridView1.RowCount - 1)) return; DataGridViewRow dgr = dataGridView1.Rows[e.RowIndex]; try { if (dgr.Cells["Name"].Value.ToString() == "小明") { dgr.Cells["Name"].Style.ForeColor= Color.Red; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
支持(0) 反对(0) 清海扬波 | 园豆:825 (小虾三级) | 2011-01-25 11:18
0

dataGridView1.Columns["小名"].DefaultCellStyle.BackColor=Color.Red

imnt | 园豆:210 (菜鸟二级) | 2011-01-25 11:12
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册