views:

123

answers:

3

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 :-/

+1  A: 

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.

splash
No, this doesn't make any difference. The checkbox still toggles, and as soon as the user leaves the cell the value is posted.
Svein Bringsli
A: 

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.

evdkraan
This does make it harder to unintentionally toggle checkboxes, and it will solve the problem for people clicking on a row just to set the focus, but it will change the behaviour for the entire grid, not just checkboxes.
Svein Bringsli
But this keeps the handling consistent! You are trying to introduce a special cell/editor which behaves different. Maybe it's time for a customer training!? ;-)
splash
I'd love to, but we have very few customers, and we can't risk to alienate them :-)
Svein Bringsli
A: 

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.

Svein Bringsli
That was definitly the best place to ask. The support from *DevExpress* is superior!
splash