Select
TsgcHTMLComponent_Select — Delphi、C++ Builder、.NET で、optgroup、複数選択、サイズ調整、データセットバインディングを備えた Bootstrap 5 のセレクトドロップダウンです。
TsgcHTMLComponent_Select — Delphi、C++ Builder、.NET で、optgroup、複数選択、サイズ調整、データセットバインディングを備えた Bootstrap 5 のセレクトドロップダウンです。
ラベル付きの Bootstrap form-select を出力するドロップダウンです。オプションを追加し(またはデータセットをバインドし)、任意でそれらをグループ化して複数選択を許可してから、HTML プロパティを読み取ります。
TsgcHTMLComponent_Select
Bootstrap 5 の form-select
Delphi, C++ Builder, .NET
Name、Label_、Placeholder を設定し、AddOption(または AddOptionGroup)でオプションを追加してから、HTML を読み取ります(または TsgcHTMLTemplate_Bootstrap ページに組み込みます)。
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
最もよく使うメンバーです。
Options は TsgcHTMLSelectOption のコレクションです(各項目は Value、Text、Selected、Disabled、Group を持ちます)。便利メソッドの AddOption(value, text, selected) と AddOptionGroup(group, value, text) がこれを埋めます。
Name はフィールド名を、Label_ はキャプションを、Placeholder は無効な先頭オプションを、SelectID は要素 id(既定値は sel_<Name>)を設定します。
Multiple はこれを複数選択リストに変え、VisibleItems は一度に表示する行数(size 属性)を設定します。
Size は TsgcHTMLSelectSize です — ssDefault、ssSmall、ssLarge。
LoadFromDataSet(aDataSet, aValueField, aTextField, aGroupField) は、クエリからオプションを埋め、グループフィールドが指定されると <optgroup> を構築します。ライブ更新には DataSource を割り当てます。
Required と Disabled はコントロールにフラグを立てます。HTML は、すべてのオプションと optgroup を含むラベル付きの <select> を返します。