Subject [IBO]Focus lost when tabbing into empty Grid - possible fix.
Author Paul Hope
Hello

This was raised before as 'Strange behaviour tabbing into empty grid?' but
apart from sympathy from Dany and a promise to try and find an existing work
around it wasnt resolved.

V 4.7.16

When tabbing into a IB_Grid which is empty by virtue of the query parameter
causing the query to return no data (or the table is empty) the focus first
steps invisibly through the empty row before going into insert mode.

To recreate

Place a Tedit (or anything to have the focus) on a form and an IB_Grid with
datasource, query and connection.

Make sure the Tedit is the active control.

Connect to the employee database. Set the query SQL to 'select
cust_no,customer from customer where country=:country', set key_links to
cust_no, set requestlive to true.

In the form OnCreate do

ib_query1.parambyname('country').AsString='XXX';

ib_query1.open;

Run it

focus will start in the Tedit. press TAB. nothing appears to happen (the
focus is invisible but in cust_no). Press TAB again - nothing appears to
happen (focus is invisible but in customer). Press TAB again now in insert
mode.

I have a possible fix which appears to work but the grid is a nightmare so
it will take bigger brains than mine to decide if its OK.

I have taken the code from TIB_CustomGrid.KeyDown for when NextRow detects
EOF and put it into TIB_CustomGrid.CMEnter as follows

procedure TIB_CustomGrid.CMEnter( var Message: TCMEnter );
var
AGridCoord: TGridCoord;
begin
inherited;
// It seems a pity to call this on every entry, its only needed
// on the first time after the lookup dataset has been prepared.
// Without this the tabstop may not have been initialised properly.
UpdateColumnAttributes;

// When freshly entering the grid the focused cell is likely not properly
// initialized. Especially with the use of embedded controls.
FFocusedCell.X := -1;
FFocusedCell.Y := -1;

AGridCoord.X := Col;
AGridCoord.Y := Row;
SetFocusedCell( AGridCoord );
if not PositionControl( Col, Row, CellRect( Col, Row )) then
SysUpdateEditor;
// ********added by Paul to fix loss of focus when tabbing into empty grid
with Datalink.BDataset do
begin
if DataLink.EOF and CanInsert and not Self.ReadOnly and
not Self.PreventInserting then
begin
if DataSource.AutoInsert then
begin
CheckPreventModifications;
Append;
end;
end;
end;
// ******end of Paul
end;


Can this be evaluated?

Regards

Paul



[Non-text portions of this message have been removed]