TStringGridでセルを結合するには?

解決


MIKI  2005-04-21 07:16:26  No: 14406

はじめまして、宜しくお願いします。
TStringGridにおいてセルの結合をしたいと考えています。
過去ログを参考に以下のように作成しましたが
結合したセルの隣のセルの色が変わってしまったり、
セルの境界線がずれたりします。

5列目までで
1行目と2行目がFixedの時セルが結合されるというものです。
(DrawCellプロシージャーで)

  with TStringGrid(Sender) do begin
    DefaultDrawing := True;
    if ((ACol < 6) and (gdFixed in State)) then begin
      DefaultDrawing := False;
      case ARow of
        0 : Rect.Bottom  := Rect.Bottom  + RowHeights[1] - 1;
        1 : Rect.Top := Rect.Top + RowHeights[0] - 1;
      end;
      Canvas.Brush.Color := clBtnFace;
      Canvas.Font.Color  := clBlack;
      Canvas.FillRect(Rect);
      DrawEdge(Canvas.Handle, Rect, BDR_RAISEDINNER, BF_RECT);
      DrawText(Canvas.Handle, PChar(Cells[ACol, ARow]), -1, Rect,
         DT_SINGLELINE or DT_CENTER or DT_VCENTER);
    end
    else
    begin
      DefaultDrawing := True;
      Canvas.FillRect(Rect);
      DrawText(Canvas.Handle, PChar(Cells[ACol, ARow]), -1, Rect,
         DT_SINGLELINE or DT_CENTER or DT_VCENTER);
    end;
  end;

ご教授お願いします。
また、この方法で駄目ならセル結合可能なコンポーネントも探そうかと考えています。
良いコンポーネントがありましたら教えてください。


deldel  2005-04-21 18:31:02  No: 14407

範囲選択できないけど・・・

  with TStringGrid(Sender) do begin
    if ((ACol < 6) and (gdFixed in State) and (ARow < 2)) then begin
      case ARow of
        0 : Rect.Bottom  := Rect.Bottom  + RowHeights[1];
        1 : Rect.Top := Rect.Top - (RowHeights[0] + 1);
      end;
      Canvas.Brush.Color := clBtnFace;
      Canvas.Font.Color  := clBlack;
      Canvas.FillRect(Rect);
      DrawEdge(Canvas.Handle, Rect, BDR_RAISEDINNER, BF_RECT);
      DrawText(Canvas.Handle, PChar(Cells[ACol, ARow]), -1, Rect,
         DT_SINGLELINE or DT_CENTER or DT_VCENTER);
    end else begin
      Canvas.Font.Color  := clBlack;

      if gdFixed in State then begin
        Canvas.Brush.Color := clBtnFace;
        Canvas.FillRect(Rect);
        DrawEdge(Canvas.Handle, Rect, BDR_RAISEDINNER, BF_RECT);
      end else begin
        Canvas.Brush.Color := clWindow;
        Canvas.FillRect(Rect);
      end;
      DrawText(Canvas.Handle, PChar(Cells[ACol, ARow]), -1, Rect,
         DT_SINGLELINE or DT_CENTER or DT_VCENTER);
    end;
  end;


deldel  2005-04-21 18:32:04  No: 14408

あ、DefaultDrawing は 常に False で。


deldel  2005-04-21 18:40:08  No: 14409

以下を最後に付けて下さい。

    if gdFocused in State then
      Canvas.DrawFocusRect(Rect);


MIKI  2005-04-22 06:04:21  No: 14410

deldelさん有り難う御座いました。
無事に解決いたしました。
またよろしくお願いします。


MIKI  2005-04-22 06:05:01  No: 14411

解決チェックを忘れました。


※返信する前に利用規約をご確認ください。

※Google reCAPTCHA認証からCloudflare Turnstile認証へ変更しました。






  このエントリーをはてなブックマークに追加