datagridview 怎么根据条件设置某一行背景颜色 如根据datagridview 某一列的字段值, 如列1 = “值1” 的行 设置背景颜色 其他值得不便 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e) { //为包含有特定值的行改变样式 for (int i = 0; i < this.GridView1.Rows.Count; i++) {//为了对全部数据行都有用 // string strlbl = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "[GMargin%]"));//取出行中City字段绑定的值 string strlbl = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "[GMargin%]"));//取出行中City字段绑定的值 strlbl = strlbl.Replace("%", ""); if (strlbl!="") { double lbl = Convert.ToDouble(strlbl); if (lbl > 10) {//如果他的值大于10 e.Row.BackColor = System.Drawing.Color.Orange ; } } } } 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); } } 楼主,换个CommBox 不是更好? 下拉列表框。 如何实现如迅雷7的更换皮肤效果(高分求助) c#如何让实现搜索本地磁盘文件 写库问题 comboBox数据重复和绑定数据库后再加一个选择 C#网络Socket中Bind错误.求救 请指教DataView中的数据导入EXCEL的方法 菜鸟发问:如何实现在两个窗体之间的相互切换? 百分求解存储过程错误提示----在线等待 DataGrid显示问题 通过object.GetType().ToString()可以获得控件的信息。如何在代码中把字符串转换成代码识别类型,显示该控件的属性呢? 字符串转换的问题,菜鸟,最好给出源码 C#添加系统右击菜单选项的问题
{
//为包含有特定值的行改变样式
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{//为了对全部数据行都有用
// string strlbl = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "[GMargin%]"));//取出行中City字段绑定的值
string strlbl = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "[GMargin%]"));//取出行中City字段绑定的值
strlbl = strlbl.Replace("%", "");
if (strlbl!="")
{
double lbl = Convert.ToDouble(strlbl);
if (lbl > 10)
{//如果他的值大于10
e.Row.BackColor = System.Drawing.Color.Orange ;
}
}
}
}
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);
} }
楼主,换个CommBox 不是更好? 下拉列表框。