Subject Re: [IBO] Re: Moving column in a grid
Author Helen Borrie
At 02:07 AM 12-11-02 +0000, you wrote:
>Hi Marco,
>
>Yes, IB_Grid. I'm still getting used to the fact that the dataset
>drives the controls! But it is starting to sink in now!!
>(Although it's been quite steep, I'm thoroughly enjoying the
>learning curve for IBO!
>It makes sense once you get your head around it ;) )

It's been fun watching you evolve into an IBO programmer. :-)


>That said, I've tried your suggestion but it still does not go to
>the field I'm trying to select.
>What I'm doing is setting a value in another field, then trying to
>move the focus to the next field:
>
>if not qryOrder.FieldByName('STOCK_ID').IsNull then begin
> qryOrder.FieldByName('Desc').AsString := 'SAMPLE';
> qryOrder.FieldByName('Qty').FocusControl;
>end
>else
> raise Exception.Create('Must have a stock item!');
>
>I have stepped through this code, and the .FocusControl proc is
>definately being called, but nothing seems to happen.
>The focus remains on the 'Desc' field.

FocusControl theoretically should work and, because it isn't, I'd guess
that either a) the SelectedField property (still on 'Desc') is overruling
it or b) at the time you call FocusControl, the ib_datasource hasn't yet
updated the dataset and so FocusControl isn't finding the conditions you
think it ought to.

Try assigning the SelectedField property of the grid *first*, to try and
force the focus off the Desc field. That should cause the dataset to get
updated, so SelectedField might do the job for you alone. If not, keep the
FocusControl there as well, but following the Grid.SelectedField call.

So we'd have now:

if not qryOrder.FieldByName('STOCK_ID').IsNull then begin
qryOrder.FieldByName('Desc').AsString := 'SAMPLE';
MyGrid.SelectedField := qryOrder.FieldByName('Desc');
// qryOrder.FieldByName('Qty').FocusControl;
end
else
raise Exception.Create('Must have a stock item!');

Helen