Select

TsgcHTMLComponent_Select — un menu a discesa select Bootstrap 5 con optgroup, selezione multipla, dimensionamento e binding ai dataset, in Delphi, C++ Builder e .NET.

TsgcHTMLComponent_Select

Un menu a discesa che emette un form-select Bootstrap con etichetta. Aggiungi le opzioni (oppure collega un dataset), raggruppale facoltativamente e consenti la selezione multipla, quindi leggi la proprietà HTML.

Classe del componente

TsgcHTMLComponent_Select

Renderizza

Bootstrap 5 form-select

Famiglia

Moduli e Campi

Linguaggi

Delphi, C++ Builder, .NET

Crealo, aggiungi le opzioni, renderizzalo

Imposta Name, Label_ e un Placeholder, aggiungi le opzioni con AddOption (oppure AddOptionGroup), quindi leggi HTML (oppure inseriscilo in una pagina 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

Proprietà e metodi principali

I membri che utilizzerai più spesso.

Opzioni

Options è una collezione di TsgcHTMLSelectOption (ciascuna con Value, Text, Selected, Disabled e Group); i metodi pratici AddOption(value, text, selected) e AddOptionGroup(group, value, text) la riempiono.

Identità

Name imposta il nome del campo, Label_ la didascalia, Placeholder un’opzione iniziale disabilitata e SelectID l’id dell’elemento (il valore predefinito è sel_<Name>).

Modalità di selezione

Multiple lo trasforma in una lista a selezione multipla e VisibleItems imposta quante righe vengono mostrate contemporaneamente (l’attributo size).

Dimensionamento

Size è un TsgcHTMLSelectSizessDefault, ssSmall o ssLarge.

Binding ai dataset

LoadFromDataSet(aDataSet, aValueField, aTextField, aGroupField) riempie le opzioni da una query, costruendo <optgroup> quando viene fornito un campo di gruppo; assegna DataSource per l’aggiornamento live.

Stato e output

Required e Disabled contrassegnano il controllo; HTML restituisce il <select> con etichetta con tutte le opzioni e gli optgroup.

Continua a esplorare

Tutti i componenti sgcHTMLEsplora la matrice completa delle funzionalità di oltre 60 componenti.
Scarica la Prova GratuitaLa prova di 30 giorni include i progetti demo 60.HTML.
PrezziLicenze Single, Team e Site con codice sorgente completo.

Pronto a Iniziare?

Scarica la versione di prova gratuita e inizia a creare interfacce web in Delphi, C++ Builder e .NET.