public class DataGridEx : DataGrid
     {
       ..........
       protected override void OnPaint(PaintEventArgs e){
       base.OnPaint(e);//继承原始绘制动作
       System.Windows.Forms.DataGrid.HitTestInfo myHitTest;
       myHitTest = this.HitTest(e.ClipRectangle.X,e.ClipRectangle.Y);
       //检查是否为cell
       if(myHitTest.Type==System.Windows.Forms.DataGrid.HitTestType.Cell){
         try{
           //这里myHitTest.Row Column 分别表示行和列的索引你可以取得值写判断了
           string s = dataGrid[myHitTest.Row,myHitTest.Column].ToString();
           //下面是绘制动作
           RectangleF ef1;
           Rectangle rectangle1 = this.GetCellBounds(myHitTest.Row,myHitTest.Column);
           SolidBrush brush1 = new SolidBrush(this.dataGrid.BackColor);
           StringFormat format1 = new StringFormat();
           brush1.Color = this.dataGrid.BackColor;
           e.Graphics.FillRectangle(brush1, rectangle1);
           brush1.Color = Color.Red;
           ef1 = new RectangleF((float) rectangle1.X, (float) (rectangle1.Y + 2), (float) rectangle1.Width, (float) (rectangle1.Height - 2));
           e.Graphics.DrawString(s,dataGrid.Font,brush1,ef1,format1);
         }catch{;}
       }请问如何根据datagrid中的一列的值改变行的颜色
原创
             ©著作权归作者所有:来自51CTO博客作者biyusr216的原创作品,请联系作者获取转载授权,否则将追究法律责任        
             
            
        
                提问和评论都可以,用心的回复会被更多人看到
                评论
            
            
                    发布评论
                
            
            相关文章
        
        
- 
                    YOLO入门教程(番外):目标检测的一阶段学习方法特征图的每个单元格对应原始图像的一个小方块, #YOLO #目标检测 #学习方法 目标检测 损失函数
 
 
                    













 
                    

 
                 
                    