Solved

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

Posted on 2000-05-09
4
959 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

919 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now