Back to Devexpress

CalculateCheckStatesValue(TcxCheckStates,IcxCheckItems,TcxCheckStatesValueFormat) Method

vcl-cxcheckbox-dot-calculatecheckstatesvalue-x28-4dcb8020-x29.md

latest6.6 KB
Original Source

CalculateCheckStatesValue(TcxCheckStates,IcxCheckItems,TcxCheckStatesValueFormat) Method

Calculates an edit value from specified check box item states.

Declaration

delphi
function CalculateCheckStatesValue(const ACheckStates: TcxCheckStates; AItems: IcxCheckItems; AValueFormat: TcxCheckStatesValueFormat): TcxEditValue;

Parameters

NameTypeDescription
ACheckStatesTcxCheckStates

The source array of check box states.

| | AItems | IcxCheckItems |

Check box items of the source editor with multiple check boxes, for example, the Properties.Items property of a TcxCheckGroup editor.

| | AValueFormat | TcxCheckStatesValueFormat |

The check box state value format.

This parameter value specifies the required data format of the calculated edit value.

|

Returns

TypeDescription
TcxEditValue

The calculated edit value.

The AValueFormat parameter defines the value’s format.

|

Remarks

You can call CalculateCheckStates and CalculateCheckStatesValue global functions to convert a combination of individual check box states into an edit value and vice versa. These operations can be useful for scenarios that involve interaction between editors with multiple check boxes (such as check groups and check combo boxes) and dataset fields.

Code Examples

Initialize Check Combo Box States

The following code example initializes all states for three check box items in an in-place TcxCheckComboBox editor:

delphi
uses
  cxCheckBox, // Declares the CalculateCheckStatesValue global function
  cxCheckComboBox; // Declares the TcxCheckComboBoxProperties class
//...

procedure TMyForm.cxButton1Click(Sender: TObject);
var
  AProperties: TcxCheckComboBoxProperties;
begin
  AProperties := cxBarEditItem1.Properties as TcxCheckComboBoxProperties;
  cxBarEditItem1.EditValue := CalculateCheckStatesValue([cbsChecked, cbsUnchecked, cbsChecked],
     AProperties.Items, AProperties.EditValueFormat);
end;
cpp
#include "cxCheckBox.hpp" // Declares the CalculateCheckStatesValue global function
#include "cxCheckComboBox.hpp" // Declares the TcxCheckComboBoxProperties class

// Add the following linker directives to the corresponding CPP source file
#pragma link "cxCheckBox" // Required to use cxCheckBox.hpp declarations
#pragma link "cxCheckComboBox" // Required to use cxCheckComboBox.hpp declarations
// ...

void __fastcall TMyForm::cxButton1Click(Sender: TObject)
{
  TcxCheckComboBoxProperties *AProperties;
  TcxCheckStates ACheckStates;
  ACheckStates.Length = 3;
  ACheckStates[0] = cbsChecked;
  ACheckStates[1] = cbsUnchecked;
  ACheckStates[2] = cbsChecked;
  AProperties = dynamic_cast<TcxCheckComboBoxProperties*>(cxBarEditItem1->Properties);
  cxBarEditItem1->EditValue = CalculateCheckStatesValue(ACheckStates,
    interface_cast<IcxCheckItems>(AProperties->Items), AProperties->EditValueFormat);
}

Create Check Combo Box Items and Initialize Checked States

The code example in this section does the following:

  • Populates an existing TcxCheckComboBox editor with five items ( Circle , Rectangle , Ellipse , Triangle , and Square ).

  • Calls the CalculateCheckStatesValue global function to initialize checked/unchecked states for the first four editor items using the Value property. The last item ( Square ) remains unchecked.

  • Delphi

  • C++

delphi
uses
  cxCheckBox, // Declares the CalculateCheckStatesValue global function
  cxCheckComboBox; // Declares the TcxCheckComboBox class and related types
// ...

procedure TMyForm.FormCreate(Sender: TObject);
var
  AProperties: TcxCheckComboBoxProperties;
begin
  AProperties := cxCheckComboBox1.Properties;
  // Populate the check combo box with five items
  AProperties.BeginUpdate; // Initiates the following batch operation
  try
    AProperties.Items.AddCheckItem('Circle');
    AProperties.Items.AddCheckItem('Rectangle');
    AProperties.Items.AddCheckItem('Ellipse');
    AProperties.Items.AddCheckItem('Triangle');
    AProperties.Items.AddCheckItem('Square');
  finally
    AProperties.EndUpdate(); // Calls EndUpdate regardless of the batch operation's success
  end;
  cxCheckComboBox1.Value := CalculateCheckStatesValue([cbsUnchecked, cbsUnchecked,
    cbsChecked, cbsChecked], AProperties.Items, AProperties.EditValueFormat);
end;
cpp
#include "cxCheckBox.hpp" // Declares the CalculateCheckStatesValue global function
#include "cxCheckComboBox.hpp" // Declares the TcxCheckComboBox class and related types

// Add the following linker directives to the corresponding CPP source file:
#pragma link "cxCheckBox" // Required to use cxCheckBox.hpp declarations
#pragma link "cxCheckComboBox" // Required to use cxCheckComboBox.hpp declarations
// ...

void __fastcall TMyForm::FormCreate(TObject *Sender)
{
  TcxCheckStates ACheckStates;
  SetLength(ACheckStates, 4);
  ACheckStates[0] = cbsUnchecked;
  ACheckStates[1] = cbsUnchecked;
  ACheckStates[2] = cbsChecked;
  ACheckStates[3] = cbsChecked;
  TcxCheckComboBoxProperties *AProperties = cxCheckComboBox1->Properties;
  // Populate the check combo box with five items
  AProperties->BeginUpdate(); // Initiates the following batch operation
  try
  {
    AProperties->Items->AddCheckItem("Circle");
    AProperties->Items->AddCheckItem("Rectangle");
    AProperties->Items->AddCheckItem("Ellipse");
    AProperties->Items->AddCheckItem("Triangle");
    AProperties->Items->AddCheckItem("Square");
  }
  __finally
  {
    AProperties->EndUpdate(); // Calls EndUpdate regardless of the batch operation's success
  }
  cxCheckComboBox1->Value = CalculateCheckStatesValue(ACheckStates,
  interface_cast<IcxCheckItems>(AProperties->Items), AProperties->EditValueFormat);
}

See Also

CalculateCheckStates Global Function

cxCheckBox Unit