Einzelnen Beitrag anzeigen

Benutzerbild von APP
APP

Registriert seit: 24. Feb 2003
Ort: Graz (A)
705 Beiträge
 
Delphi 7 Enterprise
 
#2

Re: Stringgrid Zellen verbinden

  Alt 13. Nov 2003, 20:11
Hallo 1adavin,

ich hatte vor kurzem ein ähnliches Problem:

Es gib 2 Möglichkeiten, Du suchst Dir eine Stringgrid-Komponente die das kann,
oder Du machst es von Hand:

Ich bin auf einen News-Group Artikel von Peter Below gestoßen, dort gibt Peter einen Tip
wie es funktioniert (der Rest ist Handarbeit ).

Delphi-Quellcode:
// In article <3ebe97dc@newsgroups.borland.com>, Stefan Deutschen wrote:
// > Is it possible to link (or better, merge) Rows or Columns in a StringGrid
// > like you can do in excel?

// You have to fake it, the grid has no direct support for such cells. Getting
// a display that looks like merged cells is the smaller problem, making the
// merged cell editable and selectable is very hard to do.

// There are lots of 3rd-party grids around, some of which should offer this
// capability.

// Draw merged cells on a stringgrid

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  i, x, y: Integer;
begin
  If gdFixed In State Then Exit;
  If ARow > 1 Then Exit;

  // draw row 1 with text from cell 1,1 spanning all cells in the row
  with sender as tstringgrid do begin
    {extend rect to include grid line on right, if not last cell
     in row}

    If aCol < Pred(ColCount) Then
      Rect.Right := Rect.Right + GridlineWidth;
      
    {figure out where the text of the first cell would start relative
     to the current cells rect. }
  
    y:= Rect.Top + 2;
    x:= Rect.Left + 2;
    for i:= 1 to aCol-1 do
      x:= x - ColWidths[i] - GridlineWidth;
      
    { Paint cell pale yellow}  
    Canvas.Brush.Color := $7FFFFF;
    Canvas.Brush.Style := bsSolid;
    Canvas.FillRect( Rect );
    
    { Paint text of cell 1,1 clipped to current cell. }
    Canvas.TextRect( Rect, x, y, Cells[1,1] );
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  i, k: Integer;
begin
  with stringgrid1 do begin
    cells[1, 1] := 'A rather long line which will span cells';
    for i:= 1 to colcount-1 do
      for k:= 2 to rowcount -1 do
        cells[i,k] := Format( 'Cell[%d,%d]',[i,k]);
  end;
end;
Armin P. Pressler

BEGIN
...real programmers are using C/C++ - smart developers Delphi;
END;
  Mit Zitat antworten Zitat