Solved

DBGRID Experts, Please answer this TAB question

Posted on 2000-05-10
6
236 Views
Last Modified: 2010-05-18
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???
0
Comment
Question by:rwhitaker
  • 3
  • 2
6 Comments
 
LVL 9

Accepted Solution

by:
ITugay earned 100 total points
ID: 2796205
Hi,

There is a sample how to enable all columns in DBGrid for Tab (even read only).  Call this procedure after you change ReadOnly property. The problem is that TDBGrid.TabStops is private propertry. To trick it I use class converting TDrawGrid(DBGrid1). It published there.

procedure TForm1.SpeedButton1Click(Sender: TObject);
var I : integer;
begin
  for I:=0 to DBGrid1.Columns.Count-1 do
  TDrawGrid(DBGrid1).TabStops[I]:=true;
end;

----
Igor.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2796535
? why not set the underlying tfield to readonly instead?
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2796582
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.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 27

Expert Comment

by:kretzschmar
ID: 2797024
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

0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2797088
sorry,
had misread the question,
igor you're right

meikl
0
 

Author Comment

by:rwhitaker
ID: 2823268
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to convert wav to mp3 in delphi 9 174
Thread safe  opinion 7 126
How to fill array with TArray.Create? 14 79
Delphi XE10, MySQL Query 4 127
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now