ajgonzalezm
asked on
How to ****** in a DBGrid column?
I need to 'mask' the keyboard entry to asterisks in one column of a TDBGrig and still be able to save the real characters typed to the underlying table. How?
Try this:::::::KnownProblem:It is not beign hidden during editing the cell.
procedure TForm1.DBGrid1DrawColumnCe ll(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
//DBgrid1.DefaultDrawing:= false;
var l:integer;
var s:string;
begin
DbGrid1.DefaultDrawColumnC ell(Rect,D ataCol,Col umn,State) ;
if Column.FieldName='D1' then begin //MyHidenField
if not(gdFixed in State) then begin
s:=Column.Field.AsString;
for l:=1 to length(s) do s[l]:='*';
//StatusBar1.SimpleText:=s +Format('[ %d-%d]',[R ect.Left,R Ect.Top]);
with (Sender as TDBGrid).Canvas do begin
//Font.Color:=clRed;
TextRect(Rect,Rect.Left,Re ct.Top,s);
end;
end;
end;
end;
procedure TForm1.DBGrid1DrawColumnCe
DataCol: Integer; Column: TColumn; State: TGridDrawState);
//DBgrid1.DefaultDrawing:=
var l:integer;
var s:string;
begin
DbGrid1.DefaultDrawColumnC
if Column.FieldName='D1' then begin //MyHidenField
if not(gdFixed in State) then begin
s:=Column.Field.AsString;
for l:=1 to length(s) do s[l]:='*';
//StatusBar1.SimpleText:=s
with (Sender as TDBGrid).Canvas do begin
//Font.Color:=clRed;
TextRect(Rect,Rect.Left,Re
end;
end;
end;
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Why so difficult?
-----
procedure TForm1.DBGrid1DrawColumnCe ll(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if DataCol = 1 then
DBGrid1.Canvas.TextRect(Re ct,Rect.Le ft+2,Rect. Top+2,'*** ***');
end;
-----
If you need to hide typed character in column in edit mode, then you need to override function TDBGrid.CreateEditor: TInplaceEdit;
----
Igor.
-----
procedure TForm1.DBGrid1DrawColumnCe
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if DataCol = 1 then
DBGrid1.Canvas.TextRect(Re
end;
-----
If you need to hide typed character in column in edit mode, then you need to override function TDBGrid.CreateEditor: TInplaceEdit;
----
Igor.
it's password Char since it is a descendant of TCustomEdit.