Board index » delphi » DBGrid - How to make ReadOnly col not having the focus

DBGrid - How to make ReadOnly col not having the focus

In a DBGrid, I have several "Info" fields, Read-Only. When the user tries
to write into them, the Gris does not allow it, but still those columns can
receive the focus. What I would like to do is giving those columns a kind
of property like the DBText has - showing DB info but not having the focus.
What I do now is if handling the "CellClick" event forcing the grid to do
make one of the "good" columns being selected with the "SelecteeField :=
MyGoodField" but it is not nice enough, and somehow the right-clik of the
mouse allows those columns to get focus.
Thanks in advance.
Gil Yoktan.

 

Re:DBGrid - How to make ReadOnly col not having the focus


Hi Gil

Something like the following works quite nicely. In the grids OnColEnter
Event have

procedure TForm1.DBGrid1ColEnter(Sender: TObject);
begin
  with DBGrid1 do
  begin
    if SelectedField.ReadOnly
    then
      if SelectedIndex = (Columns.Count - 1)
      then SelectedIndex := 0
      else SelectedIndex := SelectedIndex + 1;
  end;
end;

HTH
Regards
Clint.

Quote
Gil Yoktan wrote:

> In a DBGrid, I have several "Info" fields, Read-Only. When the user tries
> to write into them, the Gris does not allow it, but still those columns can
> receive the focus. What I would like to do is giving those columns a kind
> of property like the DBText has - showing DB info but not having the focus.
> What I do now is if handling the "CellClick" event forcing the grid to do
> make one of the "good" columns being selected with the "SelecteeField :=
> MyGoodField" but it is not nice enough, and somehow the right-clik of the
> mouse allows those columns to get focus.
> Thanks in advance.

Other Threads