Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Merging Cells vs FixedRow

Status
Not open for further replies.

rcloutie

Programmer
May 26, 2005
164
CA
Hi there,

Below is my code to merge cells (2 by 2) on a TStringGrid.

The problem is that the merging operation occurs on the first row (which is Fixed) and the 3d aspect of the cell doesn't fit. That is, there's still a line draw in the middle of the 2 cells (light 3d color) which is supposed to be left aligned. The text section is ok, prb is only 3d rectangle.

|------------------------|
| |----------||
| | ||
| |----------||
|------------------------|

instead of
|------------------------|
||----------------------||
|| ||
||----------------------||
|------------------------|

---------------------------------------------------------
procedure Grid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
var
ColRect: TRect;
sInfo: String;
begin
if (ARow = 0) then
with Grid1, Grid1.Canvas do
begin
if (ACol > 0) and (ACol mod 2 = 0) then
begin
ColRect := CellRect(ACol-1, 0);
Rect.Left := ColRect.Left;
FillRect(Rect);
TextRect(Rect, Rect.Left+(Rect.Right-
Rect.Left) div 2 - TextWidth(Cells[ACol-1, ARow])
div 2, Rect.Top+2, Cells[ACol-
1, ARow]);
end;
end;
end;
---------------------------------------------------------

Thank you all
 
This new code works well:
--------------------------
ColRect := CellRect(ACol-1, 0);
Rect.Left := ColRect.Left;
Canvas.FillRect(Rect);
Frame3D(Canvas, Rect, clBtnHighlight, clBtnShadow, 1);
DrawText(Canvas.Handle, PChar(Cells[ACol-1, ARow]), -1,
Rect, DT_SINGLELINE or DT_CENTER or DT_VCENTER)
--------------------------

Except one thing:

When scrolling horz, merged columns are not painted correctly. While maximizing and minizing the form restore columns merging correctly.

Any idea where to put code to refresh correctly the painting (or trap scroll event)?

Thanks for reply,

Rej Cloutier
 
Also don't forget property DefaultDrawing=False
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top