Link to home
Start Free TrialLog in
Avatar of rwhitaker
rwhitaker

asked on

DBGRID Experts, Please answer this TAB question

I have a dbgrid with approximately 12 fields from one table.  I turn some of these columns.ReadOnly properties to True and then depending on the situation I will turn them back to False.

What my problem is, is that it seems that once my readonly property for a column has been set to True, it never can be tabbed into, even if I set the ReadOnly property back to False.  I can use the arrow keys to get to that column, but Tab will not work.  If the column starts out to be ReadOnly = False then I can tab to it, but like I said as soon as I turn the ReadOnly property to True (this is in code by the way, not design time) I can never tab to it.

Any ideas???
ASKER CERTIFIED SOLUTION
Avatar of Igor UL7AAjr
Igor UL7AAjr
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kretzschmar
? why not set the underlying tfield to readonly instead?
To meikl,
I tried it before with the same result. It can't tab if TField.Readonly = true like for Column.Readonly=true. The problem is inside TDBGrid:


unit dbgrids
line 3462.
----
        if TabStops[ACol] then
        begin
          MoveCol(ACol, 0);
          Exit;
        end;
----
it explain why it don't tab.

line 4098
----
procedure TCustomDBGrid.SetColumnAttributes;
var
  I: Integer;
begin
  for I := 0 to FColumns.Count-1 do
  with FColumns[I] do
  begin
    TabStops[I + FIndicatorOffset] := Showing and not ReadOnly and DataLink.Active and
      Assigned(Field) and not (Field.FieldKind = fkCalculated) and not ReadOnlyField(Field);
    ColWidths[I + FIndicatorOffset] := Width;
  end;
  if (dgIndicator in Options) then
    ColWidths[0] := IndicatorWidth;
end;
-----
there you can see how TabStops[I] becam "false" if TField.ReadOnly = true.

------
Cheers,
Igor.
hi igor, rwhitaker,

try this

//toggle some fields on/off
procedure TForm1.Button1Click(Sender: TObject);
begin
  Table1.Fields[0].ReadOnly := not Table1.Fields[0].ReadOnly;
  Table1.Fields[3].ReadOnly := not Table1.Fields[3].ReadOnly;
  Table1.Fields[4].ReadOnly := not Table1.Fields[4].ReadOnly;
  Table1.Fields[7].ReadOnly := not Table1.Fields[7].ReadOnly;
end;

no problem with the TAB

meikl

sorry,
had misread the question,
igor you're right

meikl
Avatar of rwhitaker
rwhitaker

ASKER

I fixed my problem a little differently than this proposed solution, but it is pretty close to your answer.  Thanks for the help.

What I did was to Reset the readonly properties of the columns back to what they are in design mode and then load the form.  This seems to fix my problem.