我有 ListView (vsReport) 和 StringGrid,我想要的是如果我单击 ListView 中的某个元素,StringGrid 中的特定单元格必须更改颜色。我该怎么做?
路径填充有 1(上移)和 0(右移),它从左下角开始,到右上角结束,我必须为这些单元格着色。
感谢您的回答,我解决了我的问题,但还有另一个小问题,我怎样才能让单元格中的文本可见?FillRect 填充整个单元格。
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;