I have ListView (vsReport) and StringGrid and what I want is if I click on some element in ListView, particular cells in StringGrid have to change colors. How do I do it?
Path is filled with 1 (move up) and 0(move right), it starts in left bottom and ends in right top corner, and I have to color these cells.
Thanks for the answers, I handled with my problem, but there's another little issue, how can I leave text in cells visible? FillRect fills the entire cell.
procedure TForm1.ListView1SelectItem(Sender: TObject; Item: TListItem; Selected: Boolean);
var aRect: TRect;
a,x,y:integer;
path:string;
begin
path:=ListView1.Items[Item.Index].Caption;
x:=0;
y:=StringGrid1.RowCount;
for a := 0 to length(path) do
begin
if path[a]='1' then y:=y-1 else x:=x+1;
aRect := StringGrid1.CellRect(x-1,y-1);
StringGrid1.Canvas.Brush.Color := clBlue;
StringGrid1.Canvas.FillRect(aRect);
end;
end;
OnDrawCell
handler (see step 3) provides,Objects
property of the StringGrid for any purpose, you could employ this property for color storage by typecasting the color to and from aTObject
. Shout if you need help with that.OnDrawCell
event handler (search here on Stack Overflow for [Delphi] StringGrid OnDrawCell when in need of assistance with that).OnSelectItem
event exposes the Item which is clicked or otherwise selected.StringGrid.Repaint
should be enough.