StringGrid and cut text in cell lazarus / 8-Other ---------------------------------------------------------------------- faber · 2008-02-13 19:27 I have problem with cut string in StringGrid cell. When I align cell to right (taRightJustify) then if I put some long string to the cell it will be cut on the left side. As example if I put "-1.457873498302" then I see only 3498302 (end of string) but I want to see -1.4578... How to do that ? I know that is if I align to left (taLeftJustify) then I get string cut on end of string and I see -1.4578... but I must have align to right. sorry for my english thx for help regards faber ---------------------------------------------------------------------- vrull · 2008-02-20 01:34 Maybe this will help. Below is how I always draw cells in StringGrids: Code: [Select] procedure TForm1.StringGridDrawCell(Sender: TObject; aCol, aRow: Integer;   aRect: TRect; aState: TGridDrawState); var  nTextShift, nHorShift : integer;  sText : string; begin   with Sender as TStringGrid do     begin       if (ARow = 0) and (ACol < Columns.Count) then            sText := Columns.Items[ACol].Title.Caption       else sText := Cells[aCol, aRow];       if gdFixed in aState then           Canvas.Brush.Color := FixedColor       else         if gdSelected in aState then             begin               Canvas.Brush.Color := clHighLight;               Font.Color:= clHighLightText;             end           else             if (aRow mod 2) = 1 then Canvas.Brush.Color := Color             else Canvas.Brush.Color := AlternateColor;       Canvas.TextStyle.Clipping := true;       Canvas.TextStyle.Wordbreak := false;       nTextShift := (aRect.Bottom - aRect.Top -                      Canvas.TextHeight(sText)) div 2;       if (ACol < Columns.Count) and (Columns.Items[ACol].Alignment = taCenter) then         nHorShift := (aRect.Right - aRect.Left -                       Canvas.TextWidth(sText)) div 2       else nHorShift := 4;       Canvas.FillRect(aRect);       Canvas.TextRect(aRect, aRect.Left+nHorShift, aRect.Top+nTextShift, sText);     end; end; It calculates horizontal shift for center- and left-aligned columns. You can add here your calculation for right-aligned text as well, like Code: [Select] if (ACol < Columns.Count) and (Columns.Items[ACol].Alignment = taCenter) then if Canvas.TextWidth(sText) > (aRect.Right - aRect.Left) then nHorShift := 4 else nHorShift := (aRect.Right - aRect.Left -                       Canvas.TextWidth(sText)) - 4; The code above assumes that there is always one header row on the top. ---------------------------------------------------------------------- faber · 2008-02-20 09:53 Quote from: "vrull" It calculates horizontal shift for center- and left-aligned columns. You can add here your calculation for right-aligned text as well, like Code: [Select] if (ACol < Columns.Count) and (Columns.Items[ACol].Alignment = taCenter) then if Canvas.TextWidth(sText) > (aRect.Right - aRect.Left) then nHorShift := 4 else nHorShift := (aRect.Right - aRect.Left -                       Canvas.TextWidth(sText)) - 4; The code above assumes that there is always one header row on the top. Thnaks Canvas.TextWidth it's what I was looking for