Hi,
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.Initialize("")
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")
End Sub
If you don't need to know the index value right away (through the event), it can be worked out later with
' Index key
sc.SelectedIndex
' Text value
sc.GetItems().Get(sc.SelectedIndex)
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
Cheers
Brian