Board index » delphi » How to not show certain dbgrid columns at runtime

How to not show certain dbgrid columns at runtime

How do I turn off the display of several dbgrid
columns at runtime?

Thanks in advance.....Ed Band

 

Re:How to not show certain dbgrid columns at runtime


Quote
Edward A. Band wrote:

> How do I turn off the display of several dbgrid
> columns at runtime?

> Thanks in advance.....Ed Band

Access the Columns property and set the visible property of the target
columns to false.
Dave Bolt/UK
Analyst/Programmer
Delphi & C/C++

Re:How to not show certain dbgrid columns at runtime


Dave -

       Thanks for your reply.  I am still having difficulty getting the
syntax right.
  I have tried:
                      dbgrid1.columns[1].visible := false;
  and
                      dbgrid1.columns[1].field.visible := false;
   neither of these have worked.

                                                                -  Ed B.

Quote
Dave Bolt wrote in message <3575CEE5.3...@compuserve.com>...
>Edward A. Band wrote:

>> How do I turn off the display of several dbgrid
>> columns at runtime?

>> Thanks in advance.....Ed Band
>Access the Columns property and set the visible property of the target
>columns to false.
>Dave Bolt/UK
>Analyst/Programmer
>Delphi & C/C++

Re:How to not show certain dbgrid columns at runtime


Quote
Edward A. Band wrote:

> Dave -

>        Thanks for your reply.  I am still having difficulty getting the
> syntax right.
>   I have tried:
>                       dbgrid1.columns[1].visible := false;
>   and
>                       dbgrid1.columns[1].field.visible := false;
>    neither of these have worked.

>                                                                 -  Ed B.

> Dave Bolt wrote in message <3575CEE5.3...@compuserve.com>...
> >Edward A. Band wrote:

> >> How do I turn off the display of several dbgrid
> >> columns at runtime?

> >> Thanks in advance.....Ed Band
> >Access the Columns property and set the visible property of the target
> >columns to false.
> >Dave Bolt/UK
> >Analyst/Programmer
> >Delphi & C/C++

Sorry!
The following code does indeed hide some columns for a dataset.
You can use the columns for things like the title of the column and the
width and the color of text......
Dave

procedure TDocDataDef.DoAfterOpen(DataSet: TDataSet);
var
        i:integer;
begin
        with DataSet do
        begin
                for i:=0 to FieldCount-1 do
                begin
                        if not((LeftStr(Fields[i].FieldName,6)='FIELD_') {or
(Fields[i].FieldName='FOLDER_ID')}
                                or (Fields[i].FieldName='DATE_FILED')) then
Fields[i].Visible:=False;
                end;
        end;
end;

Other Threads