Solved

How to ****** in a DBGrid column?

Posted on 2000-05-09
4
972 Views
Last Modified: 2008-02-26
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?
0
Comment
Question by:ajgonzalezm
  • 2
4 Comments
 
LVL 26

Expert Comment

by:EddieShipman
ID: 2794771
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.
0
 
LVL 1

Expert Comment

by:yk030299
ID: 2795429
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;
0
 
LVL 1

Accepted Solution

by:
yk030299 earned 50 total points
ID: 2795460
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
//1)set
//  DBgrid1.DefaultDrawing:=false;
//2)put a TDBEdit on DBGrid1 and bind to the field you want; set
//DBEdit4.Passwordchar='*';
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;
    if (gdFocused in State) then begin
      DBEdit4.Top   :=DBGrid1.Top   +Rect.Top;
      DBEdit4.Left  :=DBGrid1.Left  +Rect.Left+1;
      DBEdit4.Width :=Column.Width;
//      DBEdit4.height:=DBGrid1.Font.Height;
    end;
  end;
end;
1
 
LVL 9

Expert Comment

by:ITugay
ID: 2799965
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.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

823 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question