请问:在StringGrid控件中,用鼠标同时选择多个单元格时,为何开始的那个单元格始终不显示被选中的蓝色背景?该如何解决?

解决方案 »

  1.   

    在你的DRAWCELLSTRINGGRID事件里写入:
    STRINGGRID。CELL(AROW,ACOL)。BRUSH。COLOR:=CLRED;
    相信这样可以的
      

  2.   

    //设置焦点单元格颜色
    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    var tmp:string;
        area:TRect;
        i,j:integer;
    begin
      with StringGrid1.Canvas do
        begin
          i := StringGrid1.Col;
          j := StringGrid1.Row;
          Rect := stringgrid1.CellRect(i,j);
          FillRect(Rect);
          Area := rect;
          InflateRect(Area, -2, -2);
          tmp := StringGrid1.Cells[i,j];
          StringGrid1.Canvas.Brush.Color := clBlue;//设置你想要的颜色;
          TextRect(Area,i, j, StringGrid1.Cells[i,j]);
          DrawText(Handle, PChar(tmp),length(tmp),Area, DT_CENTER);
        end;
    end;