在 Delphi XE2 中使用样式的字符串网格 - 滚动条不更新
我正在 Delphi XE2 中制作一个简单的应用程序,它专门使用“Carbon”样式。有一个包含数千行的大型字符串网格。我有一个过程,它循环遍历该网格的记录,执行一些工作,并在网格中进行一些更改。当进程循环时,当前正在处理的行将突出显示(通过设置 TStringGrid.Row)。
问题是,当我将样式应用于此网格时,滚动条不会随着行的更改而更改位置。循环确实在处理时正确突出显示了每一行,但是当它到达列表末尾时,右侧的滚动条仍然一直位于顶部。
如何让网格的滚动条随之移动?
这是我如何循环的示例:
procedure TForm1.Button1Click(Sender: TObject);
var
X: Integer;
begin
FStop:= False;
for X:= 1 to Grid.RowCount - 1 do begin
if FStop then Break; //Ability to stop loop
Grid.Row:= X; //Highlight current row
DoSomeLenghyWork;
ChangeSomethingOnGrid;
Application.ProcessMessages; //Keep program responding
end;
end;
当我不使用任何样式时,一切都工作得很好。
I'm making a simple application in Delphi XE2 which uses specifically the "Carbon" style. There's a large String Grid which has thousands of rows. I have a process which loops through the records of this grid, does some work, and makes some changes in the grid. As the process loops, the row which is being currently processed gets highlighted (by setting TStringGrid.Row
).
The problem is that when I apply the style to this grid, the scroll bar doesn't change position as the row is changed. The loop does properly highlight each row as it's being processed, but by the time it gets towards the end of the list, the scroll bar on the right is still all the way at the top.
How do I make the grid's scroll bar move along with it?
Here's a sample of how I'm looping:
procedure TForm1.Button1Click(Sender: TObject);
var
X: Integer;
begin
FStop:= False;
for X:= 1 to Grid.RowCount - 1 do begin
if FStop then Break; //Ability to stop loop
Grid.Row:= X; //Highlight current row
DoSomeLenghyWork;
ChangeSomethingOnGrid;
Application.ProcessMessages; //Keep program responding
end;
end;
Everything works just fine when I'm not using any styles.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果无效和重绘对您没有任何作用,请尝试调整字符串网格的大小:
网格宽度 := 网格宽度 - 1;
Grid.Width := Grid.Width + 1;
尝试使用隐藏和显示滚动条的字符串网格选项。在更新之前隐藏它们并在更新之后显示它们。也许这会迫使他们重新粉刷。
尝试移动滚动位置并将其移回原始位置。
If invalidate and repaint don't do anything for you, try resizing the string grid:
Grid.Width := Grid.Width - 1;
Grid.Width := Grid.Width + 1;
Try playing with the string grid options that hide and show the scrollbars. Hide them before you update and show them after. Perhaps that will force them to repaint.
Try moving the scroll position and moving it back to the original position.
这对我有用 - 它强制窗口重新绘制 StringGrid 的边框区域:
This worked for me - it forces windows to repaint the border area of the StringGrid: