1.如何根据TStringGrid的Cell[]的值,给每个Cell设不同的背京色,如cell[2,2]=2时,绿色,=1时兰色。2.Tquery的afterscroll事件,如何在query打开前afterscroll事件赋为空,打开后又启用afterscroll事件

解决方案 »

  1.   


    query1.afterscroll=Query1AfterScroll;
      

  2.   

    1、用第三方StringGrid,在重画时写
    2、写个方法。打开前query.afterscroll:=nil;  打开后query.afterscroll:=该方法;  
       例如:procedure ShowCurData(qry:tquery);
      

  3.   

    Query1.BeforeOpen事件:
    Query1.AfterScroll:=nil;Query1.AfterOpen事件:
    Query1.AfterScroll:=Query1AfterScroll;
      

  4.   

    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    var BkColor,FontColor:Tcolor;
    begin
    With StringGrid1 do
    begin
     If cells[acol, arow]='2' then BkColor:=clYellow else
     if cells[acol, arow]='1' then BkColor:=clBlue else
     bkColor:=clWhite;
      begin
        Canvas.Brush.Color :=BkColor;// ClBlue;
        Canvas.FillRect(Rect);
        Canvas.font.color:=ClBlack;
        Canvas.TextOut(rect.left , rect.top, cells[acol, arow]);
      end;
    end;
    end;
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      StringGrid1.Cells[2,2]:='1';
      StringGrid1.Cells[1,1]:='2';
    end;