Skip to main content

TcxCustomTextEditProperties.OnNewLookupDisplayText Event

Allows you to respond to new user input that does not match one of the automatic completion list entries.

Declaration

property OnNewLookupDisplayText: TcxNewLookupDisplayTextEvent read; write;

Remarks

You can handle the OnNewLookupDisplayText event to execute custom code when a user successfully enters a text string that does not match one of the entries accessible through the LookupItems property. For example, you can add new entries to a combo box editor’s drop-down window.

Event Occurrence

The OnNewLookupDisplayText event occurs every time the editor adds a new string to the LookupItems collection.

Note

An editor raises OnNewLookupDisplayText only if the new input value validation is successful.

Event Parameters

The following parameters are available within an OnNewLookupDisplayText event handler:

Sender
Provides access to the editor that raised the new lookup text processing event.
AText
Returns the added lookup display text string.

Refer to the TcxNewLookupDisplayTextEvent procedural type description for detailed information on all parameters accessible within an OnNewLookupDisplayText event handler.

Code Example: Add and Post a New Combo Box Value to the Bound Dataset Field

The code example in this section applies the following changes to an in-place combo box editor of the Names column in a data-aware Data Grid View:

  • Adds a new combo box item if a user enters a string that does not match any existing combo box item.
  • Creates a new record and sets the custom text entry as a value of the new cell in the Names column.
How to Test this Code Example

Follow the steps below to test this code example in your RAD Studio IDE:

  1. Copy the DFM code snippet below.
  2. Create a new project in the IDE and focus an empty form.
  3. Press Ctrl+V to populate the form with preconfigured components.
  4. Select the Names column and expand the Properties node in the Events tab of the Object Inspector.
  5. Create an empty OnNewLookupDisplayText event handler, paste the code example, and run the project.
  object cxGrid1: TcxGrid
   Left = 72
   Top = 80
   Width = 545
   Height = 200
   TabOrder = 0
   object cxGrid1DBTableView1: TcxGridDBTableView
     Navigator.Buttons.CustomButtons = <>
     ScrollbarAnnotations.CustomAnnotations = <>
     DataController.DataSource = DataSource1
     DataController.Summary.DefaultGroupSummaryItems = <>
     DataController.Summary.FooterSummaryItems = <>
     DataController.Summary.SummaryGroups = <>
     object cxGrid1DBTableView1RecId: TcxGridDBColumn
       DataBinding.FieldName = 'RecId'
       Visible = False
     end
     object cxGrid1DBTableView1Groups: TcxGridDBColumn
       DataBinding.FieldName = 'Groups'
     end
     object cxGrid1DBTableView1Names: TcxGridDBColumn
       DataBinding.FieldName = 'Names'
       PropertiesClassName = 'TcxComboBoxProperties'
       Properties.Items.Strings = (
         'Name1'
         'Name2'
         'Name3'
         'Name4')
     end
     object cxGrid1DBTableView1Values: TcxGridDBColumn
       DataBinding.FieldName = 'Values'
       Width = 54
     end
   end
   object cxGrid1Level1: TcxGridLevel
     GridView = cxGrid1DBTableView1
   end
 end
 object dxMemData1: TdxMemData
   Active = True
   Indexes = <>
   Persistent.Data = {
     5665728FC2F5285C8FFE3F04000000140000000100070047726F757073001400
     0000010006004E616D657300040000000300070056616C756573000400000009
     000600446174657300010600000047726F75703101050000004E616D6531010A
     000000017B000B00010600000047726F75703101050000004E616D6532011400
     000001CF0E0B00010600000047726F75703201050000004E616D6533011E0000
     00017A210B00010600000047726F75703201050000004E616D65340128000000
     01892B0B00}
   SortOptions = []
   Left = 520
   Top = 88
   object dxMemData1Groups: TStringField
     FieldName = 'Groups'
   end
   object dxMemData1Names: TStringField
     FieldName = 'Names'
   end
   object dxMemData1Values: TIntegerField
     FieldName = 'Values'
   end
   object dxMemData1Dates: TDateField
     FieldName = 'Dates'
   end
 end
 object DataSource1: TDataSource
   DataSet = dxMemData1
   Left = 472
   Top = 176
 end
procedure TMyForm.ComboBox(
  Sender: TObject; const AText: TCaption);
var
  AProperties: TcxComboBoxProperties;
begin
  AProperties := cxGrid1DBTableView1Names.Properties as TcxComboBoxProperties;
  dxMemData1.DisableControls;
  try
    dxMemData1.Append;
    AProperties.Items.Add(AText);
    cxGrid1DBTableView1Names.DataBinding.Field.AsString := AText;
    dxMemData1.Post;
  finally
    dxMemData1.EnableControls;
  end;
end;
See Also