我想在DBGRID控件中将查询到的某一行数据以蓝色条将此行数据高亮显示,如果实现
谢谢

解决方案 »

  1.   

    DBGrid1DrawColumnCell事件中procedure TFrmKhsf.DBGrid1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
    begin
     inherited;
      with DBGrid1 do
      begin
       if ((State = [gdSelected]) or (State=[gdSelected,gdFocused])) then
        begin
         Canvas.Font.Color :=ClYellow;
         Canvas.Brush.Color :=ClNavy;
        end
        else
        begin
          if  dmmain.ADOQKhsf.FieldByName('khbh').AsString='cw0001' then //变色条件
            Canvas.brush.Color :=ClYellow;        
        end;
        DefaultDrawColumnCell(Rect, DataCol, Column, State);// 这行很关键的,一定不要遗漏了
      end;
      

  2.   

    在DBGrid中的OnDrawColumnCell事件中实现procedure TMDIChildForm.DBGrid1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
    begin
     IF Datamodule1.ADOQuery1.FieldByName('注册标志').AsString='未注册' then 
     Begin  //判断条件
         DBGrid1.Canvas.Font.Color:=clBlue; //将字体的颜色变成蓝色
         DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
     End;
    End;
      

  3.   

    if ADOQuery1.RecNo  = 5 then
        DBGrid1.Canvas.Brush.Color := RGB(191, 255, 223);  DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);