Subject [IBO] Re: Moving column in a grid
Author Ryan Nilsson-Harding
Thanks for the suggestion Helen,
but the .SelectedField property is a read-only property so I can't
assign it any value. This was actually what I tried first.

Also, I have taken out the
...AsString := 'SAMPLE';
line of code, so that the only line is the
...('QTY').FocusControl;
but even that does not work, so I'm assuming it doesn't have
anything to do with the first line assigning data to the DESCR field.

I'm a little stumped with this.
Could it be that when .FocusControl is assigned, it is merely
focusing on the grid, instead of the column?

rgds,
-Ryan

>
> >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