Back to Devexpress

TcxEditRepositoryToggleSwitchItem Class

vcl-cxeditrepositoryitems-ae0b6c62.md

latest6.4 KB
Original Source

TcxEditRepositoryToggleSwitchItem Class

A repository item that stores toggle switch settings.

Declaration

delphi
TcxEditRepositoryToggleSwitchItem = class(
    TcxEditRepositoryItem
)

Remarks

A toggle switch is a touch-friendly version of a check box. A toggle switch replaces a check mark with a thumb whose position corresponds to the current check state.

The TcxEditRepositoryToggleSwitchItem class overrides the Properties property that allows you to access and customize toggle switch settings.

Edit Repository Items and Standalone Editors

Edit repository items are useful when you need to share the same settings between multiple editors of the same type. To accomplish this goal, you can assign the same edit repository item to RepositoryItem properties of all target editors.

Edit Repository Items and Container Controls

A container control item (such as a toolbar edit item or a column (or any other data item) in a Data Grid, Vertical Grid, or Tree List control) can embed an in-place editor shipped with the ExpressEditors Library. An in-place editor exists (and, therefore, has its own WinAPI handle) only when the target container control item is being edited. Otherwise, the container control item displays a static editor image for resource usage optimization.

Create a Toggle Switch Repository Item at Design Time

To create a toggle switch repository item at design time, double-click a TcxEditRepository component to invoke its collection editor.

The collection editor dialog allows you to manage repository items. Click the Add… button to invoke a repository item creation dialog.

Select the ToggleSwitch item and click the Ok button to create a toggle switch repository item.

Create a Toggle Switch Repository Item in Code

The following code example creates a toggle switch repository item, customizes switch settings, and assigns the created repository item to two existing unbound toggle switches:

delphi
uses cxEdit, cxEditRepositoryItems;
// ...
var
  AToggleSwitchRepositoryItem: TcxEditRepositoryToggleSwitchItem;
  ARepositoryItem: TcxEditRepositoryItem;
begin
  ARepositoryItem := cxEditRepository1.CreateItem(TcxEditRepositoryToggleSwitchItem);
  AToggleSwitchRepositoryItem := ARepositoryItem as TcxEditRepositoryToggleSwitchItem;
  AToggleSwitchRepositoryItem.Properties.Alignment := taLeftJustify; // Changes caption alignment
  // Indicates the current toggle switch state with text messages
  AToggleSwitchRepositoryItem.Properties.StateIndicator.Kind := sikText;
  AToggleSwitchRepositoryItem.Properties.StateIndicator.OffText := 'Disabled';
  AToggleSwitchRepositoryItem.Properties.StateIndicator.OnText := 'Enabled';
  // Assigns the created repository item to two existing unbound toggle switches
  dxToggleSwitch1.RepositoryItem := AToggleSwitchRepositoryItem;
  dxToggleSwitch2.RepositoryItem := AToggleSwitchRepositoryItem;
end;
cpp
#include "cxEdit.hpp"
#include "cxEditRepositoryItems.hpp"
// ...
  TcxEditRepositoryToggleSwitchItem *AToggleSwitchRepositoryItem;
  TcxEditRepositoryItem *ARepositoryItem;
  // ...
  ARepositoryItem = cxEditRepository1->CreateItem(__classid(TcxEditRepositoryToggleSwitchItem));
  AToggleSwitchRepositoryItem = dynamic_cast<TcxEditRepositoryToggleSwitchItem*>(ARepositoryItem);
  AToggleSwitchRepositoryItem->Properties->Alignment = taLeftJustify; // Changes caption alignment
  // Indicates the current toggle switch state with text messages
  AToggleSwitchRepositoryItem->Properties->StateIndicator->Kind = sikText;
  AToggleSwitchRepositoryItem->Properties->StateIndicator->OffText = "Disabled";
  AToggleSwitchRepositoryItem->Properties->StateIndicator->OnText = "Enabled";
  // Assigns the created repository item to two existing unbound toggle switches
  dxToggleSwitch1->RepositoryItem = AToggleSwitchRepositoryItem;
  dxToggleSwitch2->RepositoryItem = AToggleSwitchRepositoryItem;

Toggle Switch Repository Item Deletion

To delete all toggle switch repository items in a TcxEditRepository component, call its RemoveItems procedure and pass a reference to the TcxEditRepositoryToggleSwitchItem class as a parameter.

If you need to delete an individual toggle switch repository item, release it directly in code (call the Free procedure in Delphi or use the delete keyword in C++Builder).

Inheritance

TObject TPersistent TComponent TcxEditRepositoryItem TcxEditRepositoryToggleSwitchItem

See Also

TcxEditRepositoryCheckBoxItem Class

TcxEditRepositoryToggleSwitchItem Members

cxEditRepositoryItems Unit