- - * - WhiteUnicorn - * - -




* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >


TI3317 - Resolving Focus to a DBGrid After Focus Transfers


This TI shows how to resolve the inability of a DBGrid to receive
focus after clicking on some other control in the parent form
when the grid is on a MDI child form.

Applies to all versions of Delphi

Apparently the DBGrid has some focus control problems
when on an MDI child form.  This problem can be counteracted by
descending from  TDBGrid, and handling the mousedown
messages that indicate that focus should be going back to the 
control.  The following component fixes the problem.  Note, this
was written generically for all versions of Delphi. You may have
problems in Delphi 2 or 3 if you do not have unit aliasing set 
up correctly, in which case you will want to replace "winprocs"
and "wintypes" with "windows."


---------------------------------------------

unit FixedDBGrid;

interface

uses
  Winprocs,wintypes, Messages, SysUtils, Classes, Graphics, 
  Controls, Forms, Dialogs, Grids, DBGrids;

type
  TFixedDBGrid = class(TDBGrid)
  private
    { Private declarations }
  protected
    { Protected declarations }
  public
    { Public declarations }
    procedure WMRButtonDown(var Message: TWMRButtonDown); message
         WM_RBUTTONDOWN;
    procedure WMLButtonDown(var Message: TWMLButtonDown); message
         WM_LBUTTONDOWN;
  published
    { Published declarations }
  end;

procedure Register;

implementation


procedure TFixedDBGrid.WMRButtonDown(var Message: TWMRButtonDown);
begin
  winprocs.SetFocus(handle); {remember that winprocs in Delphi 1 only!}
  inherited;
end;
procedure TFixedDBGrid.WMLButtonDown(var Message: TWMLButtonDown);
begin
  winprocs.SetFocus(handle); {remember that winprocs in Delphi 1 only!}
  inherited;
end;
procedure Register;
begin
  RegisterComponents('Samples', [TFixedDBGrid]);
end;

end.



* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >



- - * - Anastasija aka WhiteUnicorn - * - - LJLiveJournal
PFPhotoFile