Select
TsgcHTMLComponent_Select — a Bootstrap 5 select dropdown with optgroups, multiple selection, sizing and dataset binding, in Delphi, C++ Builder and .NET.
TsgcHTMLComponent_Select — a Bootstrap 5 select dropdown with optgroups, multiple selection, sizing and dataset binding, in Delphi, C++ Builder and .NET.
A dropdown that emits a labelled Bootstrap form-select. Add options (or bind a dataset), optionally group them and allow multiple selection, then read the HTML property.
TsgcHTMLComponent_Select
Bootstrap 5 form-select
Delphi, C++ Builder, .NET
Set Name, Label_ and a Placeholder, add options with AddOption (or AddOptionGroup), then read HTML (or drop it into a TsgcHTMLTemplate_Bootstrap page).
uses
sgcHTML_Enums, sgcHTML_Component_Select;
var
oSelect: TsgcHTMLComponent_Select;
begin
oSelect := TsgcHTMLComponent_Select.Create(nil);
try
oSelect.Name := 'country';
oSelect.Label_ := 'Country';
oSelect.Placeholder := 'Select a country';
oSelect.Size := ssLarge;
oSelect.AddOption('es', 'Spain', True);
oSelect.AddOption('fr', 'France');
oSelect.AddOptionGroup('Americas', 'us', 'United States');
WebModule.Response := oSelect.HTML; // Bootstrap form-select
finally
oSelect.Free;
end;
end;
// Or fill it straight from a dataset:
oSelect.LoadFromDataSet(qryCountries, 'Code', 'Name', 'Region');
// includes: sgcHTML_Enums.hpp, sgcHTML_Component_Select.hpp
TsgcHTMLComponent_Select *oSelect = new TsgcHTMLComponent_Select(NULL);
try
{
oSelect->Name = "country";
oSelect->Label_ = "Country";
oSelect->Placeholder = "Select a country";
oSelect->Size = ssLarge;
oSelect->AddOption("es", "Spain", true);
oSelect->AddOption("fr", "France");
oSelect->AddOptionGroup("Americas", "us", "United States");
String html = oSelect->HTML; // Bootstrap form-select
}
__finally
{
delete oSelect;
}
using esegece.sgcWebSockets;
var select = new TsgcHTMLComponent_Select();
select.Name = "country";
select.Label_ = "Country";
select.Placeholder = "Select a country";
select.Size = TsgcHTMLSelectSize.ssLarge;
select.AddOption("es", "Spain", true);
select.AddOption("fr", "France");
select.AddOptionGroup("Americas", "us", "United States");
string html = select.HTML; // Bootstrap form-select
The members you reach for most often.
Options is a collection of TsgcHTMLSelectOption (each with Value, Text, Selected, Disabled and Group); the convenience methods AddOption(value, text, selected) and AddOptionGroup(group, value, text) fill it.
Name sets the field name, Label_ the caption, Placeholder a disabled lead option and SelectID the element id (defaults to sel_<Name>).
Multiple turns it into a multi-select list and VisibleItems sets how many rows show at once (the size attribute).
Size is a TsgcHTMLSelectSize — ssDefault, ssSmall or ssLarge.
LoadFromDataSet(aDataSet, aValueField, aTextField, aGroupField) fills the options from a query, building <optgroup>s when a group field is supplied; assign DataSource for live refresh.
Required and Disabled flag the control; HTML returns the labelled <select> with all options and optgroups.