Back to Devexpress

TcxCustomEditProperties.ReadOnly Property

vcl-cxedit-dot-tcxcustomeditproperties-b7b8aea0.md

latest5.4 KB
Original Source

TcxCustomEditProperties.ReadOnly Property

Specifies if the editor is in read-only mode.

Declaration

delphi
property ReadOnly: Boolean read; write;

Property Value

TypeDescription
Boolean

True if the editor is in read-only mode; otherwise, False.

|

Remarks

Set the ReadOnly property to True or False to enable or disable read-only mode. To define individual editor appearance settings in this mode, use the editor’s StyleReadOnly property.

Note

You cannot modify a data-aware editor’s value if the editor is bound to a read-only dataset field, even if the ReadOnly property is set to True.

Code Example: Implement Custom Editor Button Behavior in Read-Only Mode

The code example in this topic section demonstrates an OnPropertiesChanged event handler for a TcxImageComboBox editor.

This event handler changes editor appearance and behavior in response to ReadOnly property value changes as follows:

Read-Only Mode

Hides the predefined drop-down button and displays the custom Info button at the left editor border when the ReadOnly property value changes to True.

Normal Mode

Restores the initial editor layout and behavior when the ReadOnly property value changes back to False.

delphi
procedure TMyForm.cxImageComboBox1PropertiesChanged(Sender: TObject);
var
  AProperties: TcxImageComboBoxProperties;
  AButton: TcxEditButton;
begin
  AProperties := (Sender as TcxImageComboBoxProperties);
  if AProperties.ReadOnly then // Configures the read-only editor layout
  begin
    AProperties.BeginUpdate; // Initiates the following batch change
    try
      AProperties.Buttons.Items[0].Visible := False; // Hides the predefined drop-down button
      if AProperties.Buttons.Count = 1 then
      begin
        AButton := AProperties.Buttons.Add;
        AButton.Kind := bkText;
        AButton.Caption := 'Info';
        AButton.LeftAlignment := True;
      end;
      AProperties.Buttons.Items[1].Visible := True; // Displays the "Info" button
      AProperties.Buttons.Items[1].Default := True;
    finally
      AProperties.EndUpdate; // Calls EndUpdate regardless of the batch operation's success
    end;
  end
  else if not AProperties.ReadOnly then // Restores the initial editor layout
  begin
    AProperties.BeginUpdate; // Initiates the following batch change
    try
      AProperties.Buttons.Items[0].Visible := True; // Displays the predefined button
      AProperties.Buttons.Items[0].Default := True;
      if AProperties.Buttons.Count = 2 then
        AProperties.Buttons.Items[1].Visible := False; // Hides the "Info" button
    finally
      AProperties.EndUpdate; // Calls EndUpdate regardless of the batch operation's success
    end;
  end;
end;
cpp
void __fastcall TMyForm::cxImageComboBox1PropertiesChanged(TObject *Sender)
{
  TcxImageComboBoxProperties *AProperties;
  TcxButton *AButton;
  // ...
  AProperties = dynamic_cast<TcxImageComboBoxProperties*>(Sender);
  if(AProperties->ReadOnly) // Configures the read-only editor layout
  {
    AProperties->BeginUpdate(); // Initiates the following batch change
    try
    {
      AProperties->Buttons->Items[0]->Visible = false; // Hides the predefined drop-down button
      if(AProperties->Buttons->Count == 1)
      {
        AButton = AProperties->Buttons->Add();
        AButton->Kind = bkText;
        AButton->Caption = "Info";
        AButton->LeftAlignment = true;
      }
      AProperties->Buttons->Items[1]->Visible = true; // Displays the "Info" button
      AProperties->Buttons->Items[1]->Default = true;
    }
    __finally
    {
      AProperties->EndUpdate(); // Calls EndUpdate regardless of the batch operation's success
    }
  }
  else if(!AProperties->ReadOnly) // Restores the initial editor layout
  {
    AProperties->BeginUpdate(); // Initiates the following batch change
    try
    {
      AProperties->Buttons->Items[0]->Visible = true; // Displays the predefined button
      AProperties->Buttons->Items[0]->Default = true;
      if(AProperties->Buttons->Count == 2)
        AProperties->Buttons->Items[1]->Visible = false; // Hides the "Info" button
    }
    __finally
    {
      AProperties->EndUpdate(); // Calls EndUpdate regardless of the batch operation's success
    }
  }
}

Default Value

Unbound EditorsThe ReadOnly property’s default value is False.Data-Aware EditorsThe ReadOnly property’s default value matches the CanModify property value of the bound dataset field. See Also

TcxCustomEditProperties Class

TcxCustomEditProperties Members

cxEdit Unit