Select
TsgcHTMLComponent_Select — 一个 Bootstrap 5 下拉选择框,带有选项组、多选、尺寸和数据集绑定,适用于 Delphi、C++ Builder 和 .NET。
TsgcHTMLComponent_Select — 一个 Bootstrap 5 下拉选择框,带有选项组、多选、尺寸和数据集绑定,适用于 Delphi、C++ Builder 和 .NET。
一个下拉框,发出带标签的 Bootstrap form-select。添加选项(或绑定数据集),可选地将它们分组并允许多选,然后读取 HTML 属性。
设置 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 返回带标签的 <select>,包含所有选项和选项组。