SegmentedControl.Items

From Xojo Documentation

Property (As SegmentedControlItem() )
aSegmentedControl.Items = newSegmentedControlItem()Value
or
SegmentedControlItem()Value = aSegmentedControl.Items

New in 2010r4

Supported for all project types and targets.

The array of segments in the SegmentedControl. The array is zero-based.

Notes

Use this property to change the properties of each Segment in the SegmentedControl.

When checking the number of segments you must use syntax like:

SegmentedControl1.Items.Ubound

as

UBound(SegmentedControl1.Items)

will not compile.

Sample Code

This code loops through all the segments and changes their Titles:

Dim segment As SegmentedControlItem
For position As Integer = 0 To SegmentedControl1.Items.Ubound
segment = SegmentedControl1.Items(position)
segment.Title = Str(position)
Next

This code adds a new segment and then resizes all the segments so that they are visible:

Dim seg As New SegmentedControlItem
seg.Title = "Seg " + Str(SegmentedControl1.Items.Ubound + 1)

SegmentedControl1.Items.Append(seg)

// Resize all the segments
For i As Integer = 0 To SegmentedControl1.Items.Ubound
Dim item As SegmentedControlItem = SegmentedControl1.Items(i)
item.Width = SegmentedControl1.Width / (SegmentedControl1.Items.Ubound + 1) - 2
Next