Jump to content

Focus to dgrid when append record


mierlp

Recommended Posts

Hi

I have a form with a dbgrid and  button. This button calls a edit form AND appends a new record with this code:

  // Scherm aanroepen
  FormTableTypeAddressEdit.ShowModal;

  // Scherm aanroepen
  dmType.TypeAddress.Append;

This works in all other 70 edit forms (these forms only have dbedits and no dbgrid).

Now i have 10 forms which also contains a DBGRID (see attachment). When calling a form with a dbgrid using the code
the focus automaticly goes to the dbgrid and there's NO record appended. When removing the dbgrid from this edit form it works.!!!!

The button NIEUW is also for appending records, when i click this button the record will be append.

Any suggestions?

I use Delphi 10.3.3. / uniGui 1.90.0.1534 Professional

msedge_KItTBaFEZG.png

Link to comment
Share on other sites

3 hours ago, mierlp said:

When calling a form with a dbgrid using the code
the focus automaticly goes to the dbgrid and there's NO record appended. When removing the dbgrid from this edit form it works.!!!!

Hello, 

Can you please explain in more detail? How can we reproduce this issue? Can you make a simple testcase? 

Link to comment
Share on other sites

Hi Sherzod,

Attached a simple demo with:

  • main form
  • form1 (contains only dbedit)
  • form2 (contains dbedit + dbgrid)

How to test :

  • on mainform click on button 'Add record using form WITHOUT dbgrid
    • the record will be append and the focus goes to the dbedit
  • on mainform click on button 'Add record using form WITH' dbgrid
    • the record will NOT be append and the focus goes to the dbgrid

Do code on the buttons is both the same, only points to the other form

Regards Peter

testcase - dbgrid and append.zip

Link to comment
Share on other sites

17 minutes ago, mierlp said:

How to test :

  • on mainform click on button 'Add record using form WITHOUT dbgrid
    • the record will be append and the focus goes to the dbedit
  • on mainform click on button 'Add record using form WITH' dbgrid
    • the record will NOT be append and the focus goes to the dbgrid

Hi Peter,

Do you mean after the "click"

procedure TUniForm2.UniButton1Click(Sender: TObject);
begin
  MainForm.TableTest.Append;
  UniDBEdit1.SetFocus;
end;

?

Link to comment
Share on other sites

No

Just use the buttons on the mainform to see the different behavior.

When you click mainform.uniButton2 (WITH dbgrid) i must append a record
and not set the focus to the dbgrid. In that case the append is canceld.

Link to comment
Share on other sites

Try the following....

  • from mainform click '''Add record using form WITHOUT dbgrid'''
  • add 1-2 records from within this form
  • close that form
  • in the mainform click again '''Add record using form WITHOUT dbgrid'''
  • see what happends... 

When you in this screen adding records is no problem that works correct.

Only from within the mainform doing that...then it's going wrong

This works always when using the button without a dbgrid'

 

Link to comment
Share on other sites

8 hours ago, mierlp said:

see attachment

 

Hi Peter,

... I think at the moment you can use the following approach:

1. UniForm2:

type
  TUniForm2 = class(TUniForm)
    UniDBEdit1: TUniDBEdit;
    UniButton1: TUniButton;
    UniButton2: TUniButton;
    UniButton3: TUniButton;
    UniDBGrid1: TUniDBGrid;
    procedure UniButton1Click(Sender: TObject);
    procedure UniButton2Click(Sender: TObject);
    procedure UniButton3Click(Sender: TObject);
    procedure UniDBGrid1AfterLoad(Sender: TUniDBGrid);
  private
    { Private declarations }
  public
    { Public declarations }
    ForTheFirstTime: Boolean; // <-----
  end;
procedure TUniForm2.UniDBGrid1AfterLoad(Sender: TUniDBGrid);
begin
  if ForTheFirstTime then
  begin
    ForTheFirstTime := False;
    (Sender as TUniDBGrid).DataSource.DataSet.Append;
  end;

end;

 

2. MainForm:

procedure TMainForm.UniButton2Click(Sender: TObject);
begin
  UniForm2.ForTheFirstTime := True;
  UniForm2.showModal;
  //MainForm.TableTest.Append;
end;

 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...