Link to home
Start Free TrialLog in
Avatar of ajgonzalezm
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?
Avatar of Eddie Shipman
Eddie Shipman
Flag of United States of America image

From what I can see, you'd have to override the InPlace editor and set
it's password Char since it is a descendant of TCustomEdit.
Avatar of yk030299
yk030299

Try this:::::::KnownProblem:It is not beign hidden during editing the cell.

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
//DBgrid1.DefaultDrawing:=false;
var l:integer;
var s:string;
begin
  DbGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,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]',[Rect.Left,REct.Top]);

      with (Sender as TDBGrid).Canvas do begin
        //Font.Color:=clRed;
        TextRect(Rect,Rect.Left,Rect.Top,s);
      end;
    end;
  end;
end;
ASKER CERTIFIED SOLUTION
Avatar of yk030299
yk030299

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Why so difficult?
-----
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
   if DataCol = 1 then
   DBGrid1.Canvas.TextRect(Rect,Rect.Left+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.