Select

TsgcHTMLComponent_Select — 一个 Bootstrap 5 下拉选择框,带有选项组、多选、尺寸和数据集绑定,适用于 Delphi、C++ Builder 和 .NET。

TsgcHTMLComponent_Select

一个下拉框,发出带标签的 Bootstrap form-select。添加选项(或绑定数据集),可选地将它们分组并允许多选,然后读取 HTML 属性。

组件类

TsgcHTMLComponent_Select

渲染为

Bootstrap 5 form-select

语言

Delphi, C++ Builder, .NET

创建它、添加选项、渲染它

设置 NameLabel_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 集合(每个都带有 ValueTextSelectedDisabledGroup);便捷方法 AddOption(value, text, selected)AddOptionGroup(group, value, text) 来填充它。

标识

Name 设置字段名称,Label_ 设置标题,Placeholder 设置一个禁用的引导选项,SelectID 设置元素 id(默认为 sel_<Name>)。

选择模式

Multiple 将其变成多选列表,VisibleItems 设置一次显示多少行(size 属性)。

尺寸

Size 是一个 TsgcHTMLSelectSizessDefaultssSmallssLarge

数据集绑定

LoadFromDataSet(aDataSet, aValueField, aTextField, aGroupField) 从查询填充选项,提供分组字段时构建 <optgroup>;赋值 DataSource 可实时刷新。

状态与输出

RequiredDisabled 为控件标记状态;HTML 返回带标签的 <select>,包含所有选项和选项组。

继续探索

所有 sgcHTML 组件浏览 60 多个组件的完整功能矩阵。
下载免费试用版30 天试用版附带 60.HTML 演示项目。
价格Single、Team 和 Site 授权,均含完整源代码。

准备好开始了吗?

下载免费试用版,开始在 Delphi、C++ Builder 和 .NET 中构建 Web 界面。