Solved

DBGRID Experts, Please answer this TAB question

Posted on 2000-05-10
6
243 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month7 days, 21 hours left to enroll

617 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