Ticket T553081
Visible to All Users

How can I access which checkbox was changed/clicked in an unblund column and get its value (true/false)?

created 8 years ago

[DevExpress Support Team: CLONED FROM A1095: How to set up an unbound item in a data-aware View]
Hi,

How can I then access which checkbox was changed/clicked and its value (true/false)?

Regards

Answers approved by DevExpress Support

created 8 years ago (modified 8 years ago)

Hello Klemen,

When you click a checkbox in GridView, the record and column, where the editor is located, become focused. So, you can work with the focused record and column to determine where an in-place checkbox has been changed:

Delphi
var AValue: Boolean; begin with <AcxGridDBTableView>.DataController do AValue := Values[FocusedRecordIndex, <AUnboundColumnWithCheckBox>.Index];
    Show previous comments (3)

      Thank you Mikhail.

      This works now:

      Delphi
      cxGrid1DBTableView1.DataController.CreateAllItems; cxGrid1DBTableView1.ApplyBestFit; i := 0; GDataModule.CdsKandidatiSolaRok.First; while (not GDataModule.CdsKandidatiSolaRok.EOF) do begin AValue := GDataModule.CdsKandidatiSolaRok.FieldByName('aUniqueField').AsBoolean; cxGrid1DBTableView1.DataController.Values[i, AUnboundColumn.Index] := AValue; inc(i); GDataModule.CdsKandidatiSolaRok.Next; end;

      I was creating all grid items after I set AUnboundColumn. Instead I had to make it before. So it was always empty…

        I have one more question regarding cxGrid checkboxes. I have difficulties capturing onClick event for checkbox. I want to check in event if checkbox is "checked" or "unchecked". I'm trying in onCellClick event from cxGrid but without luck. I only managed to check if cell is checkbox. Can you please help me?

        Some events code example:

        Delphi
        procedure TFrmLastenFilter.GridKandidatiTV1CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean); begin with ACellViewInfo do if Properties is TcxCheckBoxProperties then begin // Here is your code showmessage('Is checkbox'); if GridKandidatiTV1.DataController.Values[GridKandidatiTV1.DataController.FocusedRowIndex, 0] = true then // CB checked begin showmessage('checked'); end else if GridKandidatiTV1.DataController.Values[GridKandidatiTV1.DataController.FocusedRowIndex, 0] = False then // CB unchecked begin showmessage('unchecked'); end; end else showmessage('Not checkbox'); end;

        Regards

        DevExpress Support Team 8 years ago

          I recommend you take a look at the B20752: OnCellDblClick/OnCellClick events aren't fired for a CheckBox column to learn why the OnCellClick event is not triggered for cells with CheckBoxes by default. There you can find a workaround for this behavior.
          Also, you can use the OnEditValueChanged event to accomplish the task:

          Delphi
          procedure <AForm>.<ACheckBoxColumn>PropertiesEditValueChanged(Sender: TObject); begin Caption := 'CheckBox.Checked = ' + BoolToStr(TcxCheckBox(Sender).EditValue, True); end;

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.