DBGrid lost focus when moving into the dataset
Original Reporter info from Mantis: Stefano
-
Reporter name: Stefano
Original Reporter info from Mantis: Stefano
- Reporter name: Stefano
Description:
Hello,
Since Lazarus 0.9.30 and next versions (0.9.30.2, 0.9.30.4, 1.0) I've noted that sometimes the DbGrid lost focus (Bug 0019993).
Now I've believe to have found the cause of the problem: the problem occours when moving into the record of the dataset associeted to the dbgrid (for example to calculate totals of a currency field).
If in the OnKeyDown event I wish calculate the totals of the dbgrid (if the keys are Key of deplacement (Arrows, PgUp, PdDown, Tab, ...)) and call a calcprocedure, the grid lost focus.
When the grid lost focus, it occours the problem (at run time) in case of moving between forms/windows with Alt + Tab (Bug 0022475). This is a great problem.
If I put a setfocus command after the calcprocedure, it seems to work until the user don't move on the form with Alt+Tab. After that, when the dbgrid cause the calc procedure lost focus, there are problems in inserting data in the cells, a charachter replace the previous.
I use Linux (Debian Squeeze) with GTK2.
Best regards,
Stefano
Additional information:
procedure TForm2.DBGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
[...]
//Lazarus 1.0: THIS CODE GIVE PROBLEMS WITH ALT+TAB
if (Key = 38 {KeyArrowUp}) or (Key = 40 {KeyArrowDown}) then begin
if (dbgrid1.SelectedIndex = 2) then begin
CalcTotali; //Lazarus 1.0: After that, the grid/cells lost focus!
end;
end;
[...]
end;
procedure TForm2.CalcTotali;
var
Bmk: TBookmark;
C, MyTot: Currency;
begin
C := 0;
MyTot := 0;
Label1.Caption := '';
if (SqlQuery1.Active = False) then exit;
if (SqlQuery1.RecordCount < 1) then exit;
Bmk := SqlQuery1.GetBookmark;
try
if (SqlQuery1.State in [dsEdit, dsInsert]) then SqlQuery1.Post; //Memorizza eventuali modifiche apportate
except
end;
try
SqlQuery1.DisableControls;
SqlQuery1.First;
while not SqlQuery1.EOF do begin
try
C := SqlQuery1.FieldByName('FIELD3').AsCurrency;
except
C := 0;
end;
MyTot := MyTot + C;
SqlQuery1.Next;
end;
finally
try
SqlQuery1.GotoBookmark(Bmk);
except
end;
SqlQuery1.EnableControls;
end;
Label1.Caption := CurrToStrF(MyTot, ffNumber, 2);
end;
Mantis conversion info:
- Mantis ID: 22804
- Version: 1.0.0