![]() |
Stringgrid Zellen verbinden
:-D :?:
Hallo zuammen, kann mir jemand eine Hilfestellung leisten, wie ich in einem Stringgrid z.B. in der 2. Zeile die drei Spalten 2,3+4 aus Zeile vereinige. Beispiel:
Code:
SPALTE1 SPALTE2 SPALTE3 SPALTE4 SPALTE4
1. Zeile TEXT TEXT TEXT TEXT TEXT 2. Zeile TEXT S U M M E TEXT 3. Zeile TEXT WERT1 WERT2 WERT3 TEXT In der 2. Zeile sollen die Werte der 2.,3. und 4. Zelle aus Zeile 3 addiert werden. Vielen Dank schon jetzt Gruß DAVIN :hi: |
Re: Stringgrid Zellen verbinden
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 :mrgreen:).
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; |
Re: Stringgrid Zellen verbinden
:thuimb:
Danke hat funktioniert Gruß Davin |
Alle Zeitangaben in WEZ +1. Es ist jetzt 07:46 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz