Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

syntax help for setting DBGrid field or column to invisible 1

Status
Not open for further replies.

fr2

Programmer
May 13, 2008
45
US
How do I code for a filed in the grid to have visible set to false? .. Do I code the field or column .... visible=False ...

please help with syntax .. I get this error when I compile

dgrMYGRID.Fields['dob'].Visible := False;


[Error] D_MYGRID.pas(1317): Incompatible types: 'Integer' and 'String'
 
Look up 'persistent fields' in Delphi Help. Basically, right-click the DBGrid and select 'columns editor'.
Right-click in the Columns Editor and select 'add all fields'.
Now select the fields you don't want displayed, and press 'delete'. (It doesn't delete fields from the record, just the column from the grid.)
Optionally, you can add each field one at a time, but you'll have to identify each table-field manually. You can also put them in any order on the grid, regardless of field position.

HTH


Roo
Delphi Rules!
 
Well .. I need to set the visible property ... Reason being that the form is a base form .. that is inherited by several other forms in different projects and used or modified accordingly.

I need the the whole dbgrid .. but to set the visble property to False .. so that the inherited forms can reset it to True as needed .... ( some projects need it others do not .. etc)

Just I need the right syntax .... if u can help with that ...

Thanks
 
As much as I hate repeating myself:
Look up 'persistent fields' in Delphi Help.
It will open topic "Creating a customized grid" with seven additional related links at the bottom.

If you follow my previous suggestion, you will end up with an array of TColumn. Once you have them, you can do what you asked...
Code:
  DBGrid1.Columns[2].Visible:= false;
...to hide the third column. (The first one is Column[0].) Likewise, to show them all:
Code:
var i: integer;  //array index
begin
  for i:= 0 to DbGrid1.FieldCount -1 do
    DBGrid1.Columns[i].Visible:= true;
Does that explain why you got error: Incompatible types: 'Integer' and 'String'?

Never underestimate tha powah of tha Help file!


Roo
Delphi Rules!
 
Did you get that working the way you wanted?

Roo
Delphi Rules!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top