TW3ComboBox
Represents class for SELECT HTML (drop-down) control. Most important property is Items array property.
Unit: SmartCL.Controls.ComboBox.pas
- Hierarchy
- TObject
Properties |
---|
Count |
Items |
SelectedIndex |
Values |
Methods |
Add |
Clear |
Remove |
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
Count
Determine number of items in strings array.
property Count: Integer read getCount;
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;
SelectedIndex
Specifies currently selected item.
property SelectedIndex: Integer read getSelIndex write setSelIndex;
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
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);
Clear
Delete all items from items array and set Count property to 0.
procedure Clear;
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);
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;