我想请问一下,AdvStringGrid 这个控件,我要设置某一单元格的颜色应该怎么设置。比如说我在在表格的单击事件中,去触发该事件,将当前单元的颜色改为某一种颜色。(可能表达的不是很清楚,望见谅)在此先谢谢了!

解决方案 »

  1.   

    TStringGrid都有相应的事件。
    在OnDrawCell里写代码。
    type
      TDrawCellEvent = procedure (Sender: TObject; ACol, ARow: Longint; Rect: TRect; State: TGridDrawState) of object;
    property OnDrawCell: TDrawCellEvent;在代码中判断state (TGridDrawState = set of (gdSelected, gdFocused, gdFixed) ),如果gdSelect in state 则改变颜色,否则将颜色置为默认值就可以了。 
      

  2.   

    我想问一下如果我不放OnDrawCell事件中该如何去改变某一单元格的颜色,不知道行不行。
      

  3.   

    给你一个代码例子,自己参考
    procedure TFrmOut.aGridGetCellColor(Sender: TObject; ARow, ACol: Integer;
      AState: TGridDrawState; ABrush: TBrush; AFont: TFont);
    begin
        if (StrToIntdef(agrid.Cells[18,arow],6) = 0) then
            AFont.Style := [fsBold];
    end;