当水平滚动条移动时 StringGrid 实时更新?

发布于 2024-10-01 01:54:59 字数 389 浏览 11 评论 0原文

在 Delphi 2010 中,我需要显示一个网格,该网格具有大约 15 列 x 5 行的水平滚动条。

我选择使用 StringGrid。

但是,当鼠标按钮向下拖动水平滚动条时,我希望网格实时滚动。

StringGrid 组件似乎不会实时滚动。它会等到鼠标按钮释放后才更新列并在必要时滚动。

另外,水平滚动条按钮(就是它的名字)与列数不成正比。对于在底行上的向下箭头移动到右侧下一列的顶部...

这些似乎是常见的需求,所以我很惊讶没有在 TStringGrid 中找到它们。

关于解决这两个问题的方法有什么建议吗?我可以使用 DbGrid 或其他标准组件,但我的偏好是如果可以避免的话不使用商业网格。我不会使用共享软件或免费软件......

TIA

In Delphi 2010, I need to display a grid that has a horizontal scroll bar with about 15 columns x 5 rows.

I chose to use a StringGrid.

However, while the mouse button is down dragging the horizontal scroll bar, I want the grid to scroll live.

The StringGrid component, it appears, does not scroll live. It waits until the mouse button is released before updating the column and scrolling if necessary.

Also, the horizontal scroll bar button (is that what it's called) is not proportional to the number of columns. And for a down-arrow when on the bottom row to move to the top of the next column to the right...

These seem like common needs, so I was surprised not to find them in TStringGrid.

Any suggestions on a way around these two problems? I can use a DbGrid or other standard component, but my preference is to not use a commercial grid if I can avoid it. And I'm not going to use shareware or freeware...

TIA

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浅沫记忆 2024-10-08 01:54:59

对于第一个问题,您可以在StringGrid的选项 在设计时或运行时:

StringGrid1.Options := StringGrid1.Options + [goThumbTracking];

对于第三个问题,您可以通过使用控件的键盘事件处理程序来提供您需要的功能。一个例子;

procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  StringGrid: TStringGrid;
begin
  StringGrid := Sender as TStringGrid;
  case Key of
    VK_DOWN:
      if StringGrid.Row = StringGrid.RowCount - 1 then begin
        Key := 0;
        StringGrid.Row := StringGrid.FixedRows;
        if StringGrid.Col = StringGrid.ColCount - 1 then
          StringGrid.Col := StringGrid.FixedCols
        else
          StringGrid.Col := StringGrid.Col + 1;
      end;
    VK_UP:    //...;
    VK_RIGHT: //;
    VK_LEFT:  //;
  end;
end;

对于第二个问题,滚动代码似乎被隐藏在TCustomGrid的私有方法中。我不知道如何实现这一目标..

For the first question, you can set goThumbTracking in the StringGrid's Options at design-time, or at run-time:

StringGrid1.Options := StringGrid1.Options + [goThumbTracking];

For the third question, you can provide the functionality you need by using keyboard event handlers of the control. An example;

procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  StringGrid: TStringGrid;
begin
  StringGrid := Sender as TStringGrid;
  case Key of
    VK_DOWN:
      if StringGrid.Row = StringGrid.RowCount - 1 then begin
        Key := 0;
        StringGrid.Row := StringGrid.FixedRows;
        if StringGrid.Col = StringGrid.ColCount - 1 then
          StringGrid.Col := StringGrid.FixedCols
        else
          StringGrid.Col := StringGrid.Col + 1;
      end;
    VK_UP:    //...;
    VK_RIGHT: //;
    VK_LEFT:  //;
  end;
end;

For the second question, the scrolling code seems to be buried in private methods of TCustomGrid. I have no clue how to achieve that..

爱殇璃 2024-10-08 01:54:59

如果注意到您对第三方组件 - 免费软件不感兴趣,我也不喜欢这些,但如果我们想解决问题,有时我们都必须做出牺牲。这是这些牺牲之一!这个组件非常好,不容忽视。如果你没有几年的空闲时间,你就不会自己创造出这样的东西。

要么编写一个基于 TStringGrid 的新组件(我不会——它不是最好的工具),

但要花一些时间学习 TVirtualStringTree。该组件比 TStrignGrid 领先数年。来源是可用的,并且有很多人使用它。

并且已经实现了一些事件来对滚动条的变化做出反应
OnScroll、OnShowScrollbar

http:// www.delphi-gems.com/index.php?option=com_content&task=view&id=12&Itemid=38

在 stackoverflow 上搜索,您可以阅读有关 tvirtualstringtree 的更多信息

If noticed you are not interested in third party components - Freeware, I am not fond of these either, but we all must make sacrifices sometimes if we want to get the problems solved. This is one of these sacrifices! This component is to good to be ignored. You will not create something like it yourself if you don't have a couple of years of free time.

Either write a new component based on TStringGrid (I would not - it is not the best tool in the box to begin with)

But take some time and learn TVirtualStringTree. The component is years ahead of TStrignGrid. The source is available and there are many who uses it.

And there are events already implemented to react on scrollbar changes
OnScroll, OnShowScrollbar

http://www.delphi-gems.com/index.php?option=com_content&task=view&id=12&Itemid=38

Search on stackoverflow and you can read much more about tvirtualstringtree

为你鎻心 2024-10-08 01:54:59

其次建议使用 TVirtualStringTree。使用 TStringGrid 组件就像用生锈的剪刀刺伤自己的腹部。

Second the suggestion to use TVirtualStringTree. Working with the TStringGrid component is like stabbing yourself in the belly with a rusty scissor.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文