TW3ComboBox



TW3ComboBox


Represents class for SELECT HTML (drop-down) control. Most important property is Items array property.


TW3ComboBox

Unit: SmartCL.Controls.ComboBox.pas

Hierarchy
TObject
TW3TagObj
TW3Component
TW3MovableControl
TW3CustomControl
TW3ComboBox
Properties
Property-icon.png Count
Property-icon.png Items
Property-icon.png SelectedIndex
Property-icon.png Values
Methods
Method-icon.png Add
Method-icon.png Clear
Method-icon.png Remove
Method-icon.png IndexOf


Usage Typical usage of this control is to first add new items by using Add method. Every new item create corresponding OPTION DOM object. Values array may be also set in order to specify value attribute for each option (See also: Values). Example:

W3ComboBox1.Add('Norway');
W3ComboBox1.Values[W3ComboBox1.Count - 1]:= '47';

Second step is usually reading SelectedIndex property. Example:

MyString:= W3ComboBox1.Values[W3ComboBox1.SelectedIndex];

Properties

Property-icon.png Count

Determine number of items in strings array.

property Count: Integer read getCount;

Property-icon.png Items

Sets and gets item at specified index.

property Items[index: Integer]: String read getItem write setItem;

Example:

var  i: Integer;begin  for i:= 0 to W3ComboBox1.Count - 1 do  begin    if W3ComboBox1.Items[i] = W3EditBox1.Text then    begin      // do something    end;  end;end;

Property-icon.png SelectedIndex

Specifies currently selected item.

property SelectedIndex: Integer read getSelIndex write setSelIndex;

Property-icon.png Values

Specifies value for item at same position inside array. If value is set, every OPTION will get value attribute.

property Values[index: Integer]: Variant read getValue write setValue;

Example:

W3ComboBox1.Add('Ann');
W3ComboBox1.Values[0]:= '0';
W3ComboBox1.Add('Ben');W3ComboBox1.Values[1]:= '1';
W3ComboBox1.Add('Philip');W3ComboBox1.Values[2]:= '2';

Output:

<select id="OBJ1" class="TW3ComboBox" style="visibility: visible; display: inline-block; position: absolute; 
overflow: hidden; left: 16px; top: 288px; width: 128px; 
height: 32px;">    <option value="0">Ann</option>    <option value="1">Ben</option>    
<option value="2">Philip</option></select>

Methods

Method-icon.png Add

Add new item into strings array.

function Add(aValue: String): Integer;

aValue

string
Value to be added to array.


Example:

W3ComboBox1.Add(W3EditBox1.Text);

Method-icon.png Clear

Delete all items from items array and set Count property to 0.

procedure Clear;

Method-icon.png Remove

Remove item at specified index from items array.

procedure Remove(aIndex: Integer);

aIndex

Integer
Item's index requesting to be removed.


Remarks:

It is recommended to check if item exists before deletion.


Example:

// Delete currently selected (showing) 
itemW3ComboBox1.Remove(W3ComboBox1.SelectedIndex);

Method-icon.png IndexOf

Return index (zero-based) of first occurrence of specified string inside items array. If there is no specified string within array result will be -1.

function IndexOf(aValue: String): Integer;

aValue

string
String to be found inside items array.


Example:

if W3ComboBox1.IndexOf(W3EditBox1.Text) <> -1 then
begin  
  ShowMessage('Item fond!');
end;