Einzelnen Beitrag anzeigen

Benutzerbild von Andidreas
Andidreas

Registriert seit: 27. Okt 2005
1.110 Beiträge
 
Delphi 10.1 Berlin Enterprise
 
#1

Delphi XE zentrierter Text im StringGrid

  Alt 2. Jan 2012, 17:03
aloha...

ich versuche gerade wie folgt ein stringgrid zu befüllen und die überschrift zentriert darzustellen

prozedur zum befüllen des TStringGrids:

Delphi-Quellcode:
//******************************************************************************
// prSQLiteStringGrid --> Insert SQLite Query Data into String Grid *
// Parameter --> strGrid = TStringGrid *
// qryIN = TASQLite3Query *
// Return --> *
//******************************************************************************

procedure prSQLiteStringGrid(strGrid : TStringGrid; qryIN : TASQLite3Query);

var
iCol, iMaxTextLength, iRow : Integer;

begin

  //=== Add Columns & Set Width for First Column & Default Height ==============
  strGrid.ColCount := qryIN.FieldCount +1;
  strGrid.RowCount := qryIN.RecordCount +1;
  strGrid.DefaultRowHeight := 20;
  strGrid.ColWidths[0] := 12;
  //============================================================================


  //=== Set Column Titles ======================================================
  For iCol := 0 To (qryIN.FieldCount -1) Do
  Begin
    strGrid.Cells[iCol+1, 0] := qryIN.Fields[iCol].FieldName;
  End;
  //============================================================================


  //=== Insert Data into String Grid ===========================================
  qryIN.First;
  For iRow := 1 To qryIN.RecordCount Do
  Begin
    For iCol := 0 To (qryIN.FieldCount) -1 Do
    Begin
      strGrid.Cells[iCol+1, iRow] := qryIN.Fields[iCol].Text;
    End;
    qryIN.Next;
  End;
  //============================================================================


  //=== Auto Fit Columns =======================================================
  For iCol := 1 to (strGrid.ColCount -1) Do
  Begin
    iMaxTextLength := 0;
    For iRow := 0 To (strGrid.RowCount - 1 ) Do
    Begin
      If strGrid.Canvas.TextWidth(strGrid.Cells[iCol, iRow]) > iMaxTextLength Then
      Begin
        iMaxTextLength := strGrid.Canvas.TextWidth(strGrid.Cells[iCol, iRow]);
      End;
    End;
    strGrid.ColWidths[iCol] := iMaxTextLength + 10;
  End;
  //============================================================================

end;
die überschrift versuche ich wie folgt zentriert und fett darzustellen:

Delphi-Quellcode:
procedure Tmain_form.strgrid_dataDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);

var
s : String;

begin

  s := strgrid_data.Cells[ACol, ARow];

  //=== Column Title ===========================================================
  If ARow = 0 Then
  Begin
    strgrid_data.Canvas.Font.Style := [fsBold];
    strgrid_data.Canvas.Font.Size := 9;
    DrawText(strgrid_data.canvas.Handle, PChar(s), Length(s), Rect, DT_SINGLELINE or DT_LEFT or DT_VCENTER);
  End;
  //============================================================================

end;
ich weiß nicht wieso, aber auf diese art und weise wird mir die überschrift immer 2 mal gezeichnet, einmal mit den standardeinstellungen und das zweite mal mit den modifizierten einstellungen... weiß jemand woran das liegt?
Ein Programmierer Programmiert durchschnittlich 15 Code Zeilen pro Tag
Wir sind hier doch nicht bei SAP!!!

Aber wir habens bald
  Mit Zitat antworten Zitat