开发者

In DevExpress' Quantum Grids, how do I restrict the click area of a cell with checkbox to the actual checkbox, not the entire cell

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 e开发者_如何学运维very grid in our application :-/


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜