我有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;
Run Code Online (Sandbox Code Playgroud) 如何在ListView(vsReport)中编号项?现在我有类似的东西:
Item := ListView1.Items.Add;
Item.Caption :=inttostr(Item.Index+1);
Run Code Online (Sandbox Code Playgroud)
但它仅在项目未排序时有效.如果我排序一切都是混合的.