Ciao,
non conosco quel componente, in passato mi è successo che se nel testo c'erano lettere accentate o caratteri particolari, nascondesse il tutto.
Prova a vedere se ti fa lo stesso scherzo con dati che contengono solo lettere e numeri.
Per quanto riguarda le celle su più righe, io uso questa da anni, sia in Windows che in Linux:
{Permette di scrivere una cella su più righe tramite l'utilizzo del LineEnding.
Aggiungere il richiamo della presente "procedure" all'interno della "DrawCell"}
procedure ScriviCellaSuPiuRighe(Sender:TObject; aCol, aRow:Integer; aRect:TRect; VFSistemaColori:Boolean = True; Allineamento:TAlignment = taLeftJustify);
var WrkStr:String;
DrawRect:TRect;
WrkAltRiga:Longint;
function PreparaFlags(Flags: Cardinal): Cardinal;
begin
case Allineamento of
taLeftJustify : Result:=Flags or DT_LEFT ;
taRightJustify: Result:=Flags or DT_RIGHT ;
taCenter : Result:=Flags or DT_CENTER;
else
Result:=Flags;
end;
end;
begin
with (Sender as tStringGrid), Canvas do begin
{ erase earlier contents from default drawing }
if VFSistemaColori then begin
if (aRow >= FixedRows) and (aCol >= FixedCols) then begin
//Se la riga è selezionata, e tra le opzioni della tabella
//c'è la selezione per riga, cambio il colore dello sfondo
if (aRow = Row) and (goRowSelect in Options) then begin
Brush.Color:=SelectedColor;
Font.Color:=clWhite;
end else begin
Brush.Color:=Color;
Font.Color:=clWindowText;
end;
end else begin
Brush.Color:=FixedColor;
Font.Color:=clWindowText;
end;
end;
FillRect(aRect);
{ get cell contents }
WrkStr:=Cells[aCol, aRow];
if Length(WrkStr) > 0 then begin
{ copy of cell rectangle for text sizing }
DrawRect:=aRect;
if (Pos(LineEnding, WrkStr) > 0) then begin
//Se la riga da emettere contiene "LineEnding", riformatto la cella
{$IFDEF LINUX}
//Dopo aver aggiornato Ubuntu alla 20.04, se la cella era su più righe, l'ultima riga veniva
//tagliata.
//Questo è l'unico modo "empirico" con cui sono riuscito a risolvere
WrkStr:=WrkStr + LineEnding + LineEnding + LineEnding + LineEnding;
{$ENDIF}
{ get size of text rectangle in DrawRect, with word wrap }
DrawText(Handle, PChar(WrkStr), Length(WrkStr), DrawRect, PreparaFlags(DT_CALCRECT or DT_WORDBREAK));
WrkAltRiga:=DrawRect.Bottom - DrawRect.Top;
if (WrkAltRiga > RowHeights[aRow]) then begin
//L'altezza della cella deve essere variata perché la cella ridisegnata è più alta o più bassa
//N.B. La cella potrebbe essere più bassa quando, ad esempio diminuisco l'altezza del
// font a runtime, passando ad esempio da 20 a 12
{ cell word-wraps; increase row height }
RowHeights[aRow]:=WrkAltRiga;
{$IFDEF LINUX}
//Su Linux, senza l'istruzione qui sotto, la cosa funzionerebbe solo
//dopo aver cliccato su una cella qualsiasi della riga
(Sender as TStringGrid).Repaint;
{$ENDIF}
end else begin
{ cell doesn't word-wrap }
DrawRect.Right:=aRect.Right;
FillRect(DrawRect);
DrawText(Handle, PChar(WrkStr), Length(WrkStr), DrawRect, PreparaFlags(DT_WORDBREAK));
end;
end else begin
//La cella da emettere non contiene "LineEnding": scrivo direttamente
DrawText(Handle, PChar(WrkStr), Length(WrkStr), DrawRect, PreparaFlags(DT_SINGLELINE or DT_VCENTER));
end;
end;
end;
end;
La devi richiamare nella "OnDrawCell", qui un esempio:
procedure TForm1.TabellaNoteDrawCell(Sender: TObject; aCol, aRow: Integer;
aRect: TRect; aState: TGridDrawState);
begin
ScriviCellaSuPiuRighe(Sender, aCol, aRow, aRect, False);
end;
La parte del codice che riguarda l'allineamento, magari non ti interessa, toglila pure.
Probabilmente ti servirà qualche definizione per farla funzionare, se c'è qualcosa che non ti quadra, chiedi pure, ma di sicuro non ti risponderò mai a mezzanotte !!! (mentre rispondevo ho notato l'ora in cui hai postato !!!)
Ciao, Mario
Questo è un esempio di cosa faccio io per disegnare in modo proprietario su una griglia:
procedure TFMain.SG_RisultatiDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var recttemp: TRect;
tempMisura: TMisura;
s1,s2: string;
begin
if ARow > Elenco_Misure.Count then
exit;
if (ACol = 0) and (ARow > 0) then
(Sender as TStringGrid).Canvas.TextOut(Rect.Left + 2, Rect.Top + (Rect.Height div 3), ARow.ToString);
if (ACol = 2) and (ARow >= 1) then
begin
tempMisura := Elenco_Misure.Element[Arow-1];
if Tarocco and (ARow = TaroccoMis) then
begin
s1 := '+0.000';
s2 := '-0.000';
end
else
begin
if fControlloCampioneVISU then
begin
var ntp := abs(tempMisura.nTollPositiva / 10);
if ntp < 0.015 then
begin
ntp := 0.015;
end;
var ntn := abs(tempMisura.nTollNegativa / 10);
if ntn < 0.015 then
begin
ntn := 0.015;
end;
s1 := Format('+%.3f', [ntp], LocalFormat);
s2 := Format('-%.3f', [ntn], LocalFormat);
end
else
begin
s1 := Format('+%.3f', [tempMisura.nTollPositiva], LocalFormat);
s2 := Format('-%.3f', [abs(tempMisura.nTollNegativa)], LocalFormat);
end;
end;
recttemp := Rect.SplitRect(srTop, 0.50);
if (not tempMisura.bRisultato_Measure_P) and tempMisura.bDatiValidi then
begin
(Sender as TStringGrid).Canvas.Brush.Color := clRed;
end
else
begin
if (not tempMisura.bRisultato_Measure_N) and tempMisura.bDatiValidi then
(Sender as TStringGrid).Canvas.Brush.Color := clWebLightPink;
end;
(Sender as TStringGrid).Canvas.FillRect(Recttemp);
(Sender as TStringGrid).Canvas.TextOut(Recttemp.Left + 2, Recttemp.Top + 2, s1);
recttemp := Rect.SplitRect(srBottom, 0.50);
if (not tempMisura.bRisultato_Measure_N) and tempMisura.bDatiValidi then
begin
(Sender as TStringGrid).Canvas.Brush.Color := clRed;
end
else
begin
if (not tempMisura.bRisultato_Measure_P) and tempMisura.bDatiValidi then
(Sender as TStringGrid).Canvas.Brush.Color := clWebLightPink;
end;
(Sender as TStringGrid).Canvas.FillRect(Recttemp);
(Sender as TStringGrid).Canvas.TextOut(Recttemp.Left + 2, Recttemp.Top + 2, s2);
exit;
end;
if (ACol >= 1) and (ARow >= 1) then
begin
tempMisura := Elenco_Misure.Element[Arow-1];
if Tarocco and (ARow = TaroccoMis) then
begin
case ACol of
1: begin
s1 := '0.000';
end;
3: begin
(Sender as TStringGrid).Canvas.Font.Style := [fsBold];
if tempMisura.bDatiValidi then
s1 := '0.000'
else
s1 := 'n.a.';
end;
4: begin
(Sender as TStringGrid).Canvas.Font.Style := [fsBold];
if tempMisura.bDatiValidi then
s1 := '0.000'
else
s1 := 'n.a.';
end;
end;
end
else
case ACol of
1: begin
if fControlloCampioneVISU then
begin
s1 := Format('%.3f', [tempMisura.nMisura_Camp], LocalFormat);
end
else
begin
s1 := Format('%.3f', [tempMisura.nRiferimento], LocalFormat);
end;
end;
3: begin
(Sender as TStringGrid).Canvas.Font.Style := [fsBold];
if tempMisura.bDatiValidi then
s1 := Format('%.3f', [tempMisura.nMisura], LocalFormat)
else
s1 := 'n.a.';
end;
4: begin
(Sender as TStringGrid).Canvas.Font.Style := [fsBold];
if tempMisura.bDatiValidi then
s1 := Format('%.3f', [tempMisura.nDiff], LocalFormat)
else
s1 := 'n.a.';
end;
end;
if ((not tempMisura.bRisultato_Measure_P) OR (not tempMisura.bRisultato_Measure_N)) and tempMisura.bDatiValidi then
(Sender as TStringGrid).Canvas.Brush.Color := clWebLightPink;
(Sender as TStringGrid).Canvas.FillRect(Rect);
(Sender as TStringGrid).Canvas.TextOut(Rect.Left + 2, Rect.Top + (Rect.Height div 3), s1);
end;
end;
Il codice scrive dei dati preelaborati e presenti un array (sotto forma di record).
Magari il codice è un pò criptico, ma non è complesso da capire.
EDIT: Come appare la griglia in allegato.
Ciao