Hi,
I need to color more than one cell in a grid at the same time.
I have a query from a database that returns the column and row position of the cells that need to be painted/colored. I then add these values to a multi dimensional array. The code looks something like this:
var idxarray : Integer;
arrayHighlight : array of array of Integer;
HighlightCellsFound : Boolean;
idxarray := 0;
SetLength(arrayHighlight, 10, 10); //wont be more than 10 cells to color
While not EOF do
begin
arrayHighlight[idxarray,0] := fieldbyname('col').AsInteger;
arrayHighlight[idxarray,1] := fieldbyname('col').AsInteger;
idxarray := idxarray + 1;
end;
if idxarray > 0 then HighlightCellsFound := True;
Then all the col and row coordinates of the cells that needs coloring is in the array.
The part which I cannot get right is for the grid to actually paint it. I have tried this code, but for obvious reasons it doesn't work:
procedure Tform1.stringgrid1GetCellColor(Sender: TObject; ARow,
ACol: Integer; AState: TGridDrawState; ABrush: TBrush; AFont: TFont);
var i : Integer;
begin
if (HighlightCellsFound = True) then
begin
for i := Low( arrayHighlight ) to High( arrayHighlight ) do
begin
ACol := arrayHighlight[i,0];
ARow := arrayHighlight[i,1];
if (ACol = arrayHighlight[i,0]) and (ARow = arrayHighlight[i,1]) then
begin
AFont.Color := clBlue;
ABrush.Color:=clSkyBlue;
end;
end;
HighlightCellsFound := False;
end;
end;
Can someone please assist me.
I need to color more than one cell in a grid at the same time.
I have a query from a database that returns the column and row position of the cells that need to be painted/colored. I then add these values to a multi dimensional array. The code looks something like this:
var idxarray : Integer;
arrayHighlight : array of array of Integer;
HighlightCellsFound : Boolean;
idxarray := 0;
SetLength(arrayHighlight, 10, 10); //wont be more than 10 cells to color
While not EOF do
begin
arrayHighlight[idxarray,0] := fieldbyname('col').AsInteger;
arrayHighlight[idxarray,1] := fieldbyname('col').AsInteger;
idxarray := idxarray + 1;
end;
if idxarray > 0 then HighlightCellsFound := True;
Then all the col and row coordinates of the cells that needs coloring is in the array.
The part which I cannot get right is for the grid to actually paint it. I have tried this code, but for obvious reasons it doesn't work:
procedure Tform1.stringgrid1GetCellColor(Sender: TObject; ARow,
ACol: Integer; AState: TGridDrawState; ABrush: TBrush; AFont: TFont);
var i : Integer;
begin
if (HighlightCellsFound = True) then
begin
for i := Low( arrayHighlight ) to High( arrayHighlight ) do
begin
ACol := arrayHighlight[i,0];
ARow := arrayHighlight[i,1];
if (ACol = arrayHighlight[i,0]) and (ARow = arrayHighlight[i,1]) then
begin
AFont.Color := clBlue;
ABrush.Color:=clSkyBlue;
end;
end;
HighlightCellsFound := False;
end;
end;
Can someone please assist me.