Here is a code snippet from the CustomDialog class I sent through to you another time.
Private Sub BuildReturnValues As Map
Dim mp As Map
For Each ctl As View In ControlPanel
If ctl.Tag <> "" Then
If ctl Is TextField Then
Dim tf As TextField = ctl
Else If ctl Is SegmentedControl Then
Dim sc As SegmentedControl = ctl
Dim lst As List = sc.GetItems
The code around the SegmentedControl can be called from either the "Click" or "IndexChanged" events.
Private arrSegmentControl(100) As SegmentedControl
Dim oSCItems() As String=Array As String("Yes","No")
If sTestIdValue="True" Then
I have seen a few of your posts about using the segmented control.
Did you think of using a switch instead if it is only for a Yes/No. A switch is more like a checkbox, whereas a segmented control would be more like a radio button group, where you can have more than two responses?
Without knowing your complete project, I might be way off, but thought it might be worth considering?
Also, I think your answer will confuse others as it actually answers a different question.
The heading of the post is "How do I dynamically add segments to a segment control"
Then inside the post "I need to know dynamically which segment the user selected."
The code in your answer instead defaults in the selected item based on a value (Yes/No).
Not having a go at you, but if someone searches through the posts looking to solve a similar problem, this will confuse them.
To answer the questions though: "How do I dynamically add segments to a segment control"
A segmented control accepts a List to set it's items. You can just pass a string array created dynamically whether you create it or it comes from say a iSQL query
Dim sg As SegmentedControl
sg.SetItems(Array As String("Car","Motorcycle")) ' or any list built dynamically
"I need to know dynamically which segment the user selected."
To work out which segment was selected you use the IndexChanged event
Private Sub sc_IndexChanged (Index As Int)
Msgbox("Item pressed: " & Index,"Item")
If you don't need to know the index value right away (through the event), it can be worked out later with
' Index key
' Text value
Like I said, not trying to be picky, but it makes it hard on others if the answer marked as correct does not match the question