- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
为什么 Delphi StringGrid 有时会在 OnKeyDown
之后调用 OnClick
事件?
调试截图:
我的 OnKeyDown 事件处理程序:
var
Top: Integer;
Bottom: Integer;
CurrentRow: Integer;
begin
Top := Grid.TopRow;
Bottom := Grid.TopRow + Grid.VisibleRowCount - 1;
if (Key = 38) then CurrentRow := Grid.Row - 1
else if (Key = 40) then CurrentRow := Grid.Row + 1;
// Disable OnClick because sometimes a 'TStringGrid.Click' is called anyway...
// (when clicking on form top window bar and navigating)
Grid.OnClick := nil;
if (CurrentRow < Top - 1) or (CurrentRow > Bottom + 1) then begin
if (Key = 38) then Grid.Row := Bottom
else if (Key = 40) then Grid.Row := Top;
end;
Grid.OnClick := GridClick;
end;
编辑:
当选择最后一行并按“向下”或选择第一行并按“向上”时,似乎不会触发“OnClick”。
重现方式:
将 TStringGrid 添加到表单并填充几行。添加“OnClick”和“OnKeyDown”处理程序。这两个处理方法中不需要添加具体的代码。在表单的字符串网格中选择一行,然后按键盘上的向上或向下箭头。
编辑2:
这不是解决方案,但为了防止在按向上、向下、向上翻页或向下翻页后执行“OnClick”中的代码,我在“OnKeyDown”中设置了一个变量,按下了哪个键,并检查“OnClick”中的该变量OnClick'。
编辑3:
更新了堆栈跟踪和重现方式。
最佳答案
嗯,硬编码的按键代码并没有做到一点点透明,但是当您使用方向键(上、下、左等)时,您会看到这种效果。 .) 更改选择。
为什么 OnClick
事件处理程序被调用,是因为TCustomGrid.OnKeyDown
来电 TCustomGrid.FocusCell
,调用 Click
.
到底为什么将焦点改变到另一个单元格会产生点击我不知道,我想我们必须问开发人员。也许是为了通过单击而不是键盘来模拟将焦点更改到另一个单元格时的默认行为。
由于您似乎自己处理方向键按下,也许您可以考虑通过进一步忽略该键来防止这种情况发生:
if Key in [VK_PRIOR..VK_DOWN] then
Key := 0;
关于delphi - TStringGrid:为什么 OnClick 在 OnKeyDown 之后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19052773/
我正在尝试为 TStringGrid 创建一个列编辑器(显示/隐藏列)。编辑器是一个包含列表框、标签和按钮的面板。我想直接在我的 TStringGrid 控件中创建此编辑器。 网格: type TA
我写的一段代码有一些问题。我正在使用 TStringGrid 来绘制座位图。 它应该做的是用列向下的字母和行的数字标记 fixedcol 和 fixedrow。 我的问题是我不知道如何更改我的代码,以
题: 任何人都可以在任何地方指向一篇文章或代码示例,以了解如何 在 TStringGrid 中提供编辑和范围选择? 是的,我知道有第三方网格可以做到这一点,但它是 令人沮丧的是内置网格缺乏这种基本功能
此链接/图片显示了我试图使用 TStringGrid 实现的目标。 此链接/图片显示了我下面的代码所产生的结果。 unit Unit1; interface uses Windows, Messa
我有一个包含 10 列的 TStringGrid。添加 500 行大约需要 2 秒。这是正常表现吗? 我觉得有点慢。 我正在从数据库查询中获取数据。如果我循环查询但不将结果写入 StringGrid,
我正在运行时从 CSV 文件向字符串网格添加多行,但是 StringGrid 在更新时似乎会闪烁很多,我认为会有一个 beginupadate/Endupdate 命令来停止此操作。但是我找不到它。有
我正在 Borland C++Builder IDE 中工作,使用 VCL 控件。我试图让 TStringGrid 组件根据不同形式的用户输入向下滚动到一行并突出显示该行。我已完成突出显示部分,但我不
下面是一个简单的 Delphi 表单应用程序的代码,该应用程序设置超出包含单元格的指定 TStringGrid 范围的单元格值。 运行程序并单击显示表单上的结果网格,当计数器i超过 1 时,应该会生成
是否可以将箭头指针添加到 Delphi 7 中的 String Grind 中?您知道我的意思,您可以在 DBGrid 的左侧看到箭头指针。 最佳答案 是的,但不是自动的。您需要手动显示三角形。您可以
我想为TStringGrid实现FillCell过程。我想用某种颜色填充特定单元格,但仅当未选择该单元格(行)时才可以。 procedure TMyStrGrid.FillCell(Rect: TRe
我开始学习德尔福。所以我决定从头开始编写一个像 MS Excel 这样的应用程序。在一个新的 Form1 中,我确实放置了一个仅包含 1 页的 TPageControl 组件。在那个页面中,我确实放了
我正在按照此 video 制作一个简单的数据库应用程序。当我使用 TStringGrid 而不是视频中所述的 TGrid 时,就会出现问题,因为我没有它。我有一个导航器并将所有数据加载到 TStrin
如何自动调整 TStringGrid 行 (DefaultRowHeight) 的大小以匹配所使用字体的高度?我做了类似的事情 Grid.DefaultRowHeight:= Grid.Canvas.
我有一个用 Delphi 编写的遗留应用程序,需要构建一个机制 阅读和 写作 来自/到 TStringGrid 的数据。 我没有该应用程序的源代码,没有自动化接口(interface),供应商也不太可
我担心这可能是一个“一根绳子有多长”的问题,但想知道是否有人有一些硬数据或建议。 我有一个 TStringGrid,它可能有 3,600 行,也许更多,我们还不确定。由于显示器显然没有足够的空间,因此
我的 StringGrid 有 2 列:Player 和 Scores。我必须根据玩家的得分对该表进行排序。 情况就是这样。我尝试过使用 StringGrid3.SortColRow(true, 1)
我在谷歌上搜索并找到了很多建议,但这些建议似乎已经有好几年了,而且没有任何帮助。 我有一个包含 8 列的字符串网格,一旦我获得超过几百行,就需要 2 秒多的时间来填充(我使用 GetTickCount
我将复选框 (TCheckBox) 放置在第一列的字符串网格 (TStringGrid) 中。复选框显示良好,位置正确,并且在将鼠标悬停在其上方时通过发光来响应鼠标。然而,当我单击它们时,它们不会切换
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我的表单上有一个 TStringGrid 对象,它有 1 个固定列和 1 个固定行。我希望当用户单击该行中的任何单元格时能够选择对象上的整行。此选择还必须对用户可见(我希望该行更改颜色)。 编辑:已将
我是一名优秀的程序员,十分优秀!