Solved

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

Posted on 2000-05-09
4
1,005 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
LAN or WAN ? 11 116
How to define IfThen functions in one common unit? 4 71
tvirtualstringtree freeze when load too manny images 10 88
Firemonkey DbLookupComboBox equivalent ? 2 76
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
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…

740 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