enshrentko
asked on
how to show separate digit in delphi 7 dbgrid
hi,
i need to separate the number contains in dbgrid (e.g. 45.000.500 instead of 45000500)
how can i do this in delphi 7?
thanks
i need to separate the number contains in dbgrid (e.g. 45.000.500 instead of 45000500)
how can i do this in delphi 7?
thanks
add the fields to query --> persistent fields
and set the displayformat in the fields to 0,0
or set at runtime
query.fieldbyname('fieldna me').Displ ayFormat := '0,0';
and set the displayformat in the fields to 0,0
or set at runtime
query.fieldbyname('fieldna
only works for numeric fields
and set the
thousandseparator := '.';
in your app
and set the
thousandseparator := '.';
in your app
ah, yes it's a DBGrid.
Check this solution :
procedure TForm1.DBGrid1DrawColumnCe ll(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
st : string;
sv : variant;
si : integer;
begin
with (Sender as TDBGrid), Canvas do
begin
if Column.Fieldname = 'my_field_name' then
begin
sv := Column.Field.Value;
if not (VarIsNull(sv)) then
begin
sq := Column.Field.Value;
if sq < 0 then sq := sq * -1;
if (sq = 0) or (sq < 0.01) then
begin
FillRect(Rect);
Exit;
end;
st := FormatFloat('###.###.###,# #;;-', Column.Field.Value);
if st[1] = ',' then st := '0' + st
else if pos('-,', st) > 0 then st := '-0' + copy(st,2,10);
si := round(((Rect.Right - Rect.Left) / 2)) - round(TextWidth(st) / 2);
TextRect(Rect, Rect.Left + si, Rect.Top+2, st);
end;
end;
DefaultDrawColumnCell(Rect , DataCol, Column, State);
end;
end;
procedure TForm1.DBGrid1DrawColumnCe
const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
st : string;
sv : variant;
si : integer;
begin
with (Sender as TDBGrid), Canvas do
begin
if Column.Fieldname = 'my_field_name' then
begin
sv := Column.Field.Value;
if not (VarIsNull(sv)) then
begin
sq := Column.Field.Value;
if sq < 0 then sq := sq * -1;
if (sq = 0) or (sq < 0.01) then
begin
FillRect(Rect);
Exit;
end;
st := FormatFloat('###.###.###,#
if st[1] = ',' then st := '0' + st
else if pos('-,', st) > 0 then st := '-0' + copy(st,2,10);
si := round(((Rect.Right - Rect.Left) / 2)) - round(TextWidth(st) / 2);
TextRect(Rect, Rect.Left + si, Rect.Top+2, st);
end;
end;
DefaultDrawColumnCell(Rect
end;
end;
Oops, Exit missing after line "TextRect........."
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Var
L:integer;
begin
Result:='';
L:=Length(S);
While L>3 do
begin
Result:='.'+Copy(S,L-2,3)+
L:=L-3;
S:=Copy(S,1,L);
end;
Result:=S+Result;
end;