Table of Contents

Search Edit Guide

TTMSFNCSearchEdit is an edit box that opens a dropdown list when the user types, filtering items as they go. The list supports multiple columns, category buttons, and a configurable search button. Filtering behaviour is controlled by the FilterCondition property.

Basic setup

Add items to the Items collection, set EmptyText for the placeholder, and wire OnSelect to respond when the user picks an entry from the dropdown.

// Populate the dropdown item list and handle a selection
TMSFNCSearchEdit1.Items.Add('Apple');
TMSFNCSearchEdit1.Items.Add('Banana');
TMSFNCSearchEdit1.Items.Add('Cherry');
TMSFNCSearchEdit1.Items.Add('Mango');
TMSFNCSearchEdit1.EmptyText := 'Search fruit…';

// OnSelect fires when the user picks an item from the dropdown
procedure TForm1.TMSFNCSearchEdit1Select(Sender: TObject);
begin
  Label1.Caption := 'Selected: ' + TMSFNCSearchEdit1.Text;
end;

AutoDropDown (default True) opens the list automatically as the user types. Set it to False if you want the list to appear only on explicit action.

Multi-column layout, categories, and the search button

The Columns collection defines additional display columns. Items use a tab character (#9) as the column separator. The Categories collection populates the popup on the optional category button, letting users pre-filter by group. The SearchButton adds an explicit submit button.

// Multi-column dropdown with categories and a search button
procedure TForm1.FormCreate(Sender: TObject);
var
  col: TColumnItem;
begin
  // Two columns: name and country
  col := TMSFNCSearchEdit1.Columns.Add;
  col.Width := 120;

  col := TMSFNCSearchEdit1.Columns.Add;
  col.Width := 100;

  // Items supply one tab-delimited value per column
  TMSFNCSearchEdit1.Items.Add('Paris'#9'France');
  TMSFNCSearchEdit1.Items.Add('Berlin'#9'Germany');
  TMSFNCSearchEdit1.Items.Add('Rome'#9'Italy');

  // Add filter categories to the category button popup
  TMSFNCSearchEdit1.Categories.Add('All');
  TMSFNCSearchEdit1.Categories.Add('France');

  // Show a search button on the right of the edit
  TMSFNCSearchEdit1.SearchButton.Visible := True;
  TMSFNCSearchEdit1.SearchButton.Text    := 'Go';
end;

procedure TForm1.TMSFNCSearchEdit1SearchButtonClick(Sender: TObject);
begin
  // Trigger an explicit search action when the button is clicked
  ExecuteSearch(TMSFNCSearchEdit1.Text);
end;

Filter condition and loading from a string list

FilterCondition switches between fcContains (match anywhere) and fcStartsWith. Use LoadStrings to populate the item list in one call from any TStrings source.

// Change how the user's input is matched against the item list.
// fcContains (default) matches anywhere in the item text.
// fcStartsWith matches only from the beginning.
TMSFNCSearchEdit1.FilterCondition := fcContains;

// Load items from a string list instead of adding one by one
var
  sl: TStringList;
begin
  sl := TStringList.Create;
  try
    sl.LoadFromFile('products.txt');
    TMSFNCSearchEdit1.LoadStrings(sl);
  finally
    sl.Free;
  end;
end;

// OnChange fires on every keystroke; use it to drive live filtering
procedure TForm1.TMSFNCSearchEdit1Change(Sender: TObject);
begin
  StatusBar1.Panels.Items[0].Text := 'Searching: ' + TMSFNCSearchEdit1.Text;
end;

OnChange fires on every character change, making it suitable for driving status indicators or triggering secondary searches.

Combining columns, categories, filter condition, and selection handling

The following example builds a two-column product search with a category button for filtering by type, fcContains matching, and a selection handler that populates form fields:

procedure TForm1.FormCreate(Sender: TObject);
var
  item: TTMSFNCSearchEditItem;
  cat: TTMSFNCSearchEditCategory;
begin
  TMSFNCSearchEdit1.EmptyText := 'Search products…';
  TMSFNCSearchEdit1.FilterCondition := fcContains;

  // Two columns: Name | Price
  TMSFNCSearchEdit1.Columns.Add.Width := 180;
  TMSFNCSearchEdit1.Columns.Add.Width := 80;

  // Category button
  cat := TMSFNCSearchEdit1.Categories.Add;
  cat.Caption := 'Electronics';
  cat := TMSFNCSearchEdit1.Categories.Add;
  cat.Caption := 'Clothing';

  // Items (tab-separated columns)
  for var d in [
    '1' + #9 + 'Laptop'   + #9 + '$999',
    '1' + #9 + 'Phone'    + #9 + '$699',
    '2' + #9 + 'T-Shirt'  + #9 + '$29'  ] do
  begin
    item := TMSFNCSearchEdit1.Items.Add;
    item.Text       := d;
    item.CategoryID := StrToInt(d[1]);
  end;
end;

procedure TForm1.TMSFNCSearchEdit1Select(Sender: TObject;
  AItem: TTMSFNCSearchEditItem);
begin
  edtName.Text  := AItem.Columns[0].Caption;
  edtPrice.Text := AItem.Columns[1].Caption;
end;