在winform中我怎样才能把datagrid中某行的值为"正常"的这一行设成红色呢? 能不能给些代码.谢谢了. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 靠,整个一行上的所有cell的颜色都设置成红色不就行了 上面那为大个,你说的是web吧,我说的是winform public class DataGridTextColorBoxColumn : System.Windows.Forms.DataGridTextBoxColumn { /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; private int colornumber=0; private int row=0; private Color colorname=Color.Olive; private System.Data.DataView m_bindDataView; public DataGridTextColorBoxColumn(System.ComponentModel.IContainer container) { /// /// Windows.Forms 类撰写设计器支持所必需的 /// container.Add(this); InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } public DataGridTextColorBoxColumn() { /// /// Windows.Forms 类撰写设计器支持所必需的 /// InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region 组件设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { components = new System.ComponentModel.Container(); } #endregion protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush, bool alignToRight) {// object o=this.GetColumnValueAtRow(source,rowNum); // if (o!=null) // { // if (o.ToString().SubString(0,1)<="30") // { // backBrush=new SolidBrush(Color.Red); // } // else // if (o.ToString().SubString(0,1)>"30") // { // backBrush=new SolidBrush(Color.Blue); // } // // } // int rownum=row;// if((colornumber>100)&&(rownum==rowNum))// backBrush=new SolidBrush(colorname); bool colValue = (Boolean)(this.BindingDataView[rowNum]["check_option"]); if(colValue==true) backBrush=new SolidBrush(colorname); base.Paint (g, bounds, source, rowNum, backBrush, foreBrush, alignToRight); } 将上面的]["check_option"] 换成你要转换的列名,再将这个类替换掉原先你的那个grid中的类,就可以了,至于颜色就无所谓了,可以自己看着办! 请教高手C#中BackGroundWorker的详细使用方法以及如何正确高效访问父窗体UI方法 动态控件加事件问题 关于BeginInvoke产生异常的问题。 C# 获取datatable里的一个字段 在线等 这个问题请高手指点一下??? 遇到学习C#以来第一个问题,望强人解决一下! 怎么执行 参数是sql语句 的存储过程 求救!!!!关于Remoting中的问题 救命!怎样让数据表的一个列自动生成数据?100分送上 用TcpClient连接服务器时非常慢,为什么? 我是新手,怎么把数据库中的表中的数据存放到自己定义的数组变量中?30分相送 关于C#中压缩的问题
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private int colornumber=0;
private int row=0;
private Color colorname=Color.Olive;
private System.Data.DataView m_bindDataView; public DataGridTextColorBoxColumn(System.ComponentModel.IContainer container)
{
///
/// Windows.Forms 类撰写设计器支持所必需的
///
container.Add(this);
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} public DataGridTextColorBoxColumn()
{
///
/// Windows.Forms 类撰写设计器支持所必需的
///
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush, bool alignToRight)
{
// object o=this.GetColumnValueAtRow(source,rowNum);
// if (o!=null)
// {
// if (o.ToString().SubString(0,1)<="30")
// {
// backBrush=new SolidBrush(Color.Red);
// }
// else
// if (o.ToString().SubString(0,1)>"30")
// {
// backBrush=new SolidBrush(Color.Blue);
// }
//
// }
// int rownum=row;
// if((colornumber>100)&&(rownum==rowNum))
// backBrush=new SolidBrush(colorname); bool colValue = (Boolean)(this.BindingDataView[rowNum]["check_option"]);
if(colValue==true) backBrush=new SolidBrush(colorname);
base.Paint (g, bounds, source, rowNum, backBrush, foreBrush, alignToRight);
}