AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Stringgrid Zellen verbinden

Ein Thema von 1adavin · begonnen am 13. Nov 2003 · letzter Beitrag vom 14. Nov 2003
Antwort Antwort
1adavin

Registriert seit: 28. Mai 2003
Ort: 48607 Ochtrup
17 Beiträge
 
Delphi 7 Professional
 
#1

Stringgrid Zellen verbinden

  Alt 13. Nov 2003, 19:27


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
  Mit Zitat antworten Zitat
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
1adavin

Registriert seit: 28. Mai 2003
Ort: 48607 Ochtrup
17 Beiträge
 
Delphi 7 Professional
 
#3

Re: Stringgrid Zellen verbinden

  Alt 14. Nov 2003, 18:04


Danke hat funktioniert


Gruß

Davin
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:09 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz