在 DevExpress 中量子网格,如何将带有复选框的单元格的单击区域限制为实际复选框,而不是整个单元格

发布于 2024-09-25 06:05:27 字数 250 浏览 2 评论 0原文

我使用 Delphi (2010) 和 DevExpress Quantum Grid (v. 6.52)

当我有一个带有复选框编辑器的 TcxGridColumn 时,当用户单击单元格内的任意位置时,复选框会切换。我想限制这一点,以便用户必须单击实际的复选框。

有没有简单的方法可以做到这一点?我们的应用程序中有大量的网格,其中许多带有复选框编辑器,所以我希望有一个“神奇”的小技巧来为我做到这一点。我不想为我们应用程序中的每个网格编写自定义代码:-/

I use Delphi (2010) and a DevExpress Quantum Grid (v. 6.52)

When I have a TcxGridColumn with a CheckBox editor, the checkbox toggles when the user clicks anywhere within the cell. I want to restrict this so that the user has to click on the actual checkbox.

Is there an easy way to do this? We have an enormous amount of grids in our application, many with checkbox editors, so I'm hoping for a "magic" little trick to do this for me. I would hate to write custom code for every grid in our application :-/

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

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

发布评论

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

评论(3

恋竹姑娘 2024-10-02 06:05:27

如果您(或您的客户)希望在单击单元格时复选框不会立即更改,那么将 ImmediatePost 属性设置为 false 可能会有所帮助。

If you (or your customers) want that the checkbox doesn't change immediately if you click in the cell, then it could help if you set the ImmediatePost property to false.

初相遇 2024-10-02 06:05:27

也许不是您正在寻找的确切答案,但也许它满足您客户的要求。

对于 cxGrid 中的每个单元格,您可以打开或关闭 ImmediateEditor 属性。此属性确定在单击适当的单元格后是否立即激活特定的列编辑器。

来自 cxGrid 版本 6 的帮助文件:

property ImmediateEditor: Boolean;

描述

使用 ImmediateEditor 属性来确定当用户单击适当的单元格时是否激活特定的列编辑器。如果此属性值为 False,则当焦点位于特定单元格内时按 Enter 键即可激活网格单元格编辑器。

Maybe not the exact answer you are looking for, but perhaps it satisfies your customers request.

For each cell in your cxGrid you can switch on or off the ImmediateEditor property. This property determines whether a specific column editor is activated immediately after an appropriate cell is clicked.

From the help file for cxGrid version 6:

property ImmediateEditor: Boolean;

Description

Use the ImmediateEditor property to determine whether a specific column editor is activated when a user clicks an appropriate cell. If this property value is False, then the grid cell editor is activated by pressing the Enter key when focus is located within a specific cell.

甜心 2024-10-02 06:05:27

我向 DevExpress 发送了同样的问题作为支持请求,我得到了这样的答案:

“Hello Svein。

感谢您的消息。您可以使用 GridView 的 OnMouseDown 事件处理程序实现所需的结果并在那里检查命中信息。
随附的示例显示了如何执行此任务。请尝试这个解决方案,并让我们知道您的结果。”

测试项目有一个带有复选框列的简单网格。GridView 的 OnMouseUp 事件具有以下代码:

procedure TForm1.cxGrid1TableView1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  AHitTest: TcxCustomGridHitTest;
  ACellViewInfo: TcxGridDataCellViewInfo;
  AEditViewInfo: TcxCustomCheckBoxViewInfo;
  ARect: Trect;
  AValue: Variant;
begin
   AHitTest := TcxGridSite(Sender).GridView.GetHitTest(X, Y);
   if AHitTest is TcxGridRecordCellHitTest then
   begin
     ACellViewInfo := TcxGridRecordCellHitTest(AHitTest).ViewInfo as TcxGridDataCellViewInfo;
     if ACellViewInfo.EditViewInfo is TcxCustomCheckBoxViewInfo then
     begin
       AEditViewInfo := TcxCustomCheckBoxViewInfo(ACellViewInfo.EditViewInfo);
       ARect := AEditViewInfo.CheckBoxRect;
       if PtInRect(ARect, Point(X, Y)) then
       begin
         AValue := ACellViewInfo.GridRecord.Values[ACellViewInfo.Item.Index];
         TcxGridTableView(TcxGridSite(Sender).GridView).DataController.SetEditValue(
           ACellViewInfo.Item.Index, AValue = false, evsValue);
       end;
     end;
   end;
end;

不幸的是,由于 MouseUp 事件位于网格上,而不是列,我无法为我的复选框列创建存储库项目,但至少现在我知道一种方法来做到这一点。

I sent the same question as a support request to DevExpress, and I got this answer:

"Hello Svein.

Thank you for your message. You can achieve the desired result using the GridView's OnMouseDown event handler and checking the hit information there.
Attached is an example that shows how to perform this task. Please try this solution, and let us know your results."

The test project had a simple grid with a checkbox column. The GridView's OnMouseUp-event had the following code:

procedure TForm1.cxGrid1TableView1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  AHitTest: TcxCustomGridHitTest;
  ACellViewInfo: TcxGridDataCellViewInfo;
  AEditViewInfo: TcxCustomCheckBoxViewInfo;
  ARect: Trect;
  AValue: Variant;
begin
   AHitTest := TcxGridSite(Sender).GridView.GetHitTest(X, Y);
   if AHitTest is TcxGridRecordCellHitTest then
   begin
     ACellViewInfo := TcxGridRecordCellHitTest(AHitTest).ViewInfo as TcxGridDataCellViewInfo;
     if ACellViewInfo.EditViewInfo is TcxCustomCheckBoxViewInfo then
     begin
       AEditViewInfo := TcxCustomCheckBoxViewInfo(ACellViewInfo.EditViewInfo);
       ARect := AEditViewInfo.CheckBoxRect;
       if PtInRect(ARect, Point(X, Y)) then
       begin
         AValue := ACellViewInfo.GridRecord.Values[ACellViewInfo.Item.Index];
         TcxGridTableView(TcxGridSite(Sender).GridView).DataController.SetEditValue(
           ACellViewInfo.Item.Index, AValue = false, evsValue);
       end;
     end;
   end;
end;

Unfortunately, since the MouseUp-event was on the grid, rather than the column, I can't make a repository-item for my checkbox-columns, but at least now I know a way to do it.

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