Table of Contents

Embedded Control

TTMSFNCControlPicker turns another control into picker drop-down content. Use it when the selection UI is richer than a list, color grid, or date selector.

Control picker with a custom drop-down control

Assign Drop-Down Content

Assign the embedded control through Control. The control can provide picker integration through the control picker interfaces, but the picker can also host an existing compatible control when the form handles content synchronization.

TMSFNCControlPicker1.Control := TMSFNCTreeView1;
TMSFNCControlPicker1.DropDownControlWidth := 280;
TMSFNCControlPicker1.DropDownControlHeight := 220;
TMSFNCControlPicker1.OnSetContent := TMSFNCControlPicker1SetContent;
TMSFNCControlPicker1.OnItemSelected := TMSFNCControlPicker1ItemSelected;

Size the Drop-Down

Use DropDownControlWidth, DropDownControlHeight, DropDownWidthMode, and DropDownHeightMode to choose whether the picker uses explicit dimensions, the embedded control size, item measurements, or the picker size.

TMSFNCControlPicker1.DropDownWidthMode := cwmDropDownWidth;
TMSFNCControlPicker1.DropDownHeightMode := chmDropDownHeight;
TMSFNCControlPicker1.DropDownControlWidth := 320;
TMSFNCControlPicker1.DropDownControlHeight := 240;
TMSFNCControlPicker1.AutoDropDown := True;
TMSFNCControlPicker1.AutoCloseUp := True;

Synchronize Picker Content

Handle OnSetContent when the picker text should be computed from the embedded control. Handle OnItemSelected when the hosted control reports an item selection through the picker.

procedure TForm1.TMSFNCControlPicker1SetContent(Sender: TObject; var AText: string; var AAllow: Boolean);
begin
  AText := 'Choose a category';
  AAllow := True;
end;

procedure TForm1.TMSFNCControlPicker1ItemSelected(Sender: TObject; AText: string; AItemIndex: Integer);
begin
  Caption := AText;
end;

Combining embedded control, size mode, and content synchronization

The following example hosts a TTMSFNCCalendar in the picker, sizes the drop-down to the calendar's natural size, and synchronizes the selected date back to the picker text:

procedure TForm1.FormCreate(Sender: TObject);
begin
  TMSFNCControlPicker1.Control          := TMSFNCCalendar1;
  TMSFNCControlPicker1.DropDownWidthMode  := dwmControl;
  TMSFNCControlPicker1.DropDownHeightMode := dhwmControl;
  TMSFNCControlPicker1.Text             := DateToStr(Now);
end;

procedure TForm1.TMSFNCControlPicker1SetContent(
  Sender: TObject; var AText: string);
begin
  // Called when the picker needs to update its collapsed text
  AText := DateToStr(TMSFNCCalendar1.SelectedDate);
end;

procedure TForm1.TMSFNCCalendar1DateSelected(
  Sender: TObject; ADate: TDate);
begin
  TMSFNCControlPicker1.CloseDropDown;
end;

See Also