Solved

DBGRID Experts, Please answer this TAB question

Posted on 2000-05-10
6
235 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

20 Experts available now in Live!

Get 1:1 Help Now