Solved

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

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

735 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