Board index » delphi » Changing column focus in DBGrid

Changing column focus in DBGrid

Is there a way to go to a particular column within a DBGrid?  I don't see a
method to do that.  I've tried the following but it only sets the focus to the
DBGrid and not the column.

procedure TfrmCompany.DBGrid1ColEnter(Sender:TObject);
begin
        if DBGrid1.SelectedField.FieldName = 'Company Id' then
                DBGrid1.Fields[3].FocusControl;
end;

br...@edcs.com

 

Re:Changing column focus in DBGrid


Quote
Bryan Warbelton (wi...@indirect.com) wrote:

: Is there a way to go to a particular column within a DBGrid?  I don't see a
: method to do that.  I've tried the following but it only sets the focus to the
: DBGrid and not the column.

: procedure TfrmCompany.DBGrid1ColEnter(Sender:TObject);
: begin
:       if DBGrid1.SelectedField.FieldName = 'Company Id' then
:               DBGrid1.Fields[3].FocusControl;
: end;

Use the SelectedIndex property of the TDBGrid component. This property
contains an Integer reflecting which column in the grid currently has
focus. But you can also set this property programmatically with the result
that focus moves to the specified column. Like the Fields property, the
SelectedIndex property starts counting at zero, so the code snippet would
move focus to the second column:

  DBGrid1.SelectedIndex := 1;

--
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/ Steve Koterski               _/   The opinions expressed here are    _/
_/ koter...@borland.com         _/         exclusively my own           _/
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

Other Threads