Board index » delphi » Setting DBGrid Column Color

Setting DBGrid Column Color


2003-11-11 04:59:47 AM
delphi128
Hi,
I have a grid connected to a dataset that has some read only columns. The
number of columns in the dataset varies so they cannot be created in the
grid at design time. I'd like to be able to cycle through the columns
in the grid (after the dataset has been opened) and if the field a column is
attached to is read only, make that column grey. I have tried using the
following code but it doesn't seem to do anything:
for i := 0 to Grid.Columns.Count - 1 do
begin
if Grid.Columns[i].ReadOnly then
Grid.Columns[i].Color := clBtnFace
else
Grid.Columns[i].Color := clWindow;
end;
Is this because you cannot set the column color when the columns aren't
persistant? Thanks in advance.
Richard
 
 

Re:Setting DBGrid Column Color

Need to put it in the OnDrawColumnCell event
Like this
If dbGrid1.Fields[datacol].ReadOnly then
column.Color := clGray;
"richard plimmer" <XXXX@XXXXX.COM>writes
Quote
Hi,

I have a grid connected to a dataset that has some read only columns. The
number of columns in the dataset varies so they cannot be created in the
grid at design time. I'd like to be able to cycle through the columns
in the grid (after the dataset has been opened) and if the field a column
is
attached to is read only, make that column grey. I have tried using the
following code but it doesn't seem to do anything:

for i := 0 to Grid.Columns.Count - 1 do
begin
if Grid.Columns[i].ReadOnly then
Grid.Columns[i].Color := clBtnFace
else
Grid.Columns[i].Color := clWindow;
end;

Is this because you cannot set the column color when the columns aren't
persistant? Thanks in advance.

Richard