SegmentedButton.SelectedSegmentIndex = -1 not working

Documentation says:

“Used to get or set the selected segment number. The first segment is numbered zero. […] A value of -1 means no selection.”

My SegmentedButton (named: sb_Button) is set to “Single” selection and has four segments. I want to programatically deselect a previous selected segment with this code:

sb_Button.SelectedSegmentIndex = -1

but nothing happens. Trying to select one of the segments with

sb_Button.SelectedSegmentIndex = 2

works fine, but -1 is not recognized. Is this a (known) bug or did I miss something about how to deselect segments? Or is that impossible at all?

Sounds like someone forgot to implement -1 in that function. It’s new to API 2.0 so I’m not surprised.

The old fashioned way of dealing with segmented control, iterating the segments, should still hopefully work.

for i as Integer = 0 to (sgCtrl.SegmentCount - 1)
  var oSeg as Segment = sgCtrl.SegmentAt(i)
  oSeg.Selected = false

next i

Update: Back with test results, I can confirm the initial behavior described and that iterating the segments works as expected.

2 Likes

Thanks for testing and confirmation, Tim.

So I am going to write a feedback and hope it will be corrected in a future release…

1 Like