在windForm中如何使GridView行变色 用C# 怎样使GridView中的某行背景色变红色或字体变为蓝色?而其它行保存默认色? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 DataGridViewCellStyle style;style = new DataGridViewCellStyle(); style.BackColor = Color.Red; for (int j = 0; j < DGVAnalyse.Rows.Count; j++) { if (DGVAnalyse.Rows[j].Cells[4].Value.toints() != DGVAnalyse.Rows[j].Cells[5].Value.toints()) { DGVAnalyse.Rows[j].DefaultCellStyle = style;}}是winform的datagridview private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e) { if (e.RowIndex >= dataGridView1.Rows.Count - 1) return; DataGridViewRow dgr = dataGridView1.Rows[e.RowIndex]; try { //dgr.Cells[0]是当前性别列的索引值,用以确定判断哪一列的值 if (dgr.Cells[0].Value.ToString() == "男") { //定义画笔,使用颜色是深灰。 using (SolidBrush brush = new SolidBrush(Color.DarkGray)) { //利用画笔填充当前行 e.Graphics.FillRectangle(brush, e.RowBounds); //将值重新写回当前行。 e.PaintCellsContent(e.ClipBounds); e.Handled = true; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e) { if (e.RowIndex >= dataGridView1.Rows.Count - 1) return; DataGridViewRow dgr = dataGridView1.Rows[e.RowIndex]; try { for (int i = 0; i < dataGridView1.Rows.Count; i++) { //dgr.Cells[0]是当前性别列的索引值,用以确定判断哪一列的值 if (dgr.Cells[1].Value.ToString() == "使用中") { dgr.DefaultCellStyle.BackColor = Color.Red; } else { dgr.DefaultCellStyle.BackColor = Color.Green; } } } catch (Exception) { }} private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e) { if (e.RowIndex > = dataGridView1.Rows.Count - 1) return; DataGridViewRow dgr = dataGridView1.Rows[e.RowIndex]; try { if (dgr.Cells[" "].Value.ToString()=="A ") { dgr.DefaultCellStyle.ForeColor = Color.Red } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (e != null && e.RowIndex > -1) { DataGridViewRow dr = this.dataGridView1.Rows[e.RowIndex]; string i= dr.Cells[""].Value; if (i=="1") { dr.DefaultCellStyle.ForeColor = Color.Gray; } if (i== "2") { dr.DefaultCellStyle.ForeColor = Color.Gray; } } } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { //鼠标移到GridView某一行如何改变该行的背景色 if (e.Row.RowIndex > -1 && e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#ccccff'"); e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#ffffff'"); } } 求typeof()把FORM当参数传递 谁对oracle比较精通,我这链oracle怎么连不成功 关于字段、属性的问题 重畫TabControl,請幫忙,菜鳥,最后30分送出。。。。 WebService 试用SoapHeader调不出SoapHeaderValue,少了什么? C#中如何把二进制字符串转化为二进制 我的图形控件 - Shapes dataGrid双击给分 C#中DataSet存在多个表,怎么分5个线程全部插入数据库中 为什么我的web应用程序就是无法访问SQL数据库 关于.NET 未将对象引用设置到对象的实例 vs2005读入180M的txt文件报错,什么原因啊?
style = new DataGridViewCellStyle();
style.BackColor = Color.Red;
for (int j = 0; j < DGVAnalyse.Rows.Count; j++)
{
if (DGVAnalyse.Rows[j].Cells[4].Value.toints() != DGVAnalyse.Rows[j].Cells[5].Value.toints())
{
DGVAnalyse.Rows[j].DefaultCellStyle = style;
}
}
是winform的datagridview
{
if (e.RowIndex >= dataGridView1.Rows.Count - 1)
return;
DataGridViewRow dgr = dataGridView1.Rows[e.RowIndex];
try
{
//dgr.Cells[0]是当前性别列的索引值,用以确定判断哪一列的值
if (dgr.Cells[0].Value.ToString() == "男")
{
//定义画笔,使用颜色是深灰。
using (SolidBrush brush = new SolidBrush(Color.DarkGray))
{
//利用画笔填充当前行
e.Graphics.FillRectangle(brush, e.RowBounds);
//将值重新写回当前行。
e.PaintCellsContent(e.ClipBounds);
e.Handled = true;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
} }
{
if (e.RowIndex >= dataGridView1.Rows.Count - 1)
return;
DataGridViewRow dgr = dataGridView1.Rows[e.RowIndex];
try
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
//dgr.Cells[0]是当前性别列的索引值,用以确定判断哪一列的值
if (dgr.Cells[1].Value.ToString() == "使用中")
{
dgr.DefaultCellStyle.BackColor = Color.Red;
}
else
{
dgr.DefaultCellStyle.BackColor = Color.Green;
}
}
}
catch (Exception)
{
}
}
{
if (e.RowIndex > = dataGridView1.Rows.Count - 1)
return;
DataGridViewRow dgr = dataGridView1.Rows[e.RowIndex];
try
{
if (dgr.Cells[" "].Value.ToString()=="A ")
{
dgr.DefaultCellStyle.ForeColor = Color.Red }
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
{
if (e != null && e.RowIndex > -1)
{
DataGridViewRow dr = this.dataGridView1.Rows[e.RowIndex];
string i= dr.Cells[""].Value;
if (i=="1")
{
dr.DefaultCellStyle.ForeColor = Color.Gray;
}
if (i== "2")
{
dr.DefaultCellStyle.ForeColor = Color.Gray;
}
}
}
{
//鼠标移到GridView某一行如何改变该行的背景色
if (e.Row.RowIndex > -1 && e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#ccccff'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#ffffff'");
}
}