Topic: tGrid Column color and ...

I have tried to apply Dmitry's striped tGrid row coloring script to specified single column coloring but I couldn't get it work?
In this case I just want to color specified single column cells without striped coloring.
With the following script I'm getting "List index out of bounds" error.

procedure FORM2_TableGrid2_OnChange (Sender: string);
var iRow, c, q, iCol: integer;
begin
  c := FORM2.TableGrid2.RowCount - 1;
  q := FORM2.TableGrid2.Columns.Count - 1;
  for iCol := 0 to c do
  for iRow := 0 to q do
  begin
  if iCol mod 2 = 0 then FORM2.TableGrid2.Cell[iCol,iRow].Color := clYellow;
  end;
end;

Is it possible to get date field displayed without data when there is non entered (not checked)?
Unless I'm doing something wrong, when is not checked and entered data to date field it displayes current date.

procedure Form2_TableGrid1_OnCellClick (Sender: string; ACol, ARow: Integer);
var s: string;
begin
  s := SQLExecute('SELECT birthDate FROM People WHERE id='+Form2.TableGrid1.sqlValue);
    if s <> '' then Form2.dtpMainPeopleDOB.Date := SQLDateTimeToDateTime (s)
    else Form2.dtpMainPeopleDOB.Checked := False;

    //if Form2.dtpMainPeopleDOB.Checked = False then Form2.dtpMainPeopleDOB.sqlDate := ('');
end;

In an attempt to clear date value from it my script line which is commented out as it doesn't work..

Adam
God... please help me become the person my dog thinks I am.

Re: tGrid Column color and ...

Adam,
You probably were getting the List Index Out of Bounds error because it looks like you were using the max col variable for your row loop and max row variable for your col loop. If all you want to do is color a specific col you can do the following:

procedure FORM2_TableGrid2_OnChange (Sender: string);
var iRow: integer;
begin
  for iRow := 0 to FORM2.TableGrid2.RowCount - 1 do
  begin
    FORM2.TableGrid2.Cell[1,iRow].Color := clYellow;     // This will color the entire second column in the tablegrid - No stripes
  end;
end;

For the empty dates, I had asked that same question a long time ago and Dimitry provided a workaround to trick the system for the date controls. Here it is:

if Form2.dtpMainPeopleDOB.Checked then Form2.dtpMainPeopleDOB.Format := ''
      else Form2.dtpMainPeopleDOB.Format := ' ';

You should place this on the form onShow event and then on the Form2.dtpMainPeopleDOB onChange event..

Re: tGrid Column color and ...

Hi EHW,


Thank you very much..............
Truly appreciated....................

Adam
God... please help me become the person my dog thinks I am.