Tell me please, can you sort the Items in RadioGroup in some way, for example alphabetically (of course with non-violation of the index binding)?
With the development of the application, there are more and more elements, but I don’t really want to change the indexes every time a new element is added to the middle of the list.

  • one
    Index - there is nothing more than a number in order, changing the order changes the number! Why do you need an index? - JVic
  • That's just the point, I don’t want to change the index ... I want the alphabetical sorting not to be broken in the elements while adding a new element - Konstantin78
  • And then what do you want? I understood what you do not want but did not understand what you want. And what does the index have to do with sorting? - JVic
  • Suppose there is a list of cities (in RadioGroup): Ashgabat, Kiev, Tula (with indices respectively 0, 1, 2), when adding for example the city "Madrid", I want it to have an index of 3, and in the list it went NOT after Tula, but after "Kiev" (just like sorting in a regular database, which has indices, and the data can be sorted as you please) - Konstantin78
  • 2
    No, consider that the index == number in order -1! Why do you need an index? Save your value in the object RadioGroup1.Items.AddObject('Мадрид',TObject(3)); and accordingly get your value from an integer(RadioGroup1.Items.Objects[RadioGroup1.ItemIndex]) object integer(RadioGroup1.Items.Objects[RadioGroup1.ItemIndex]) - JVic

1 answer 1

The index is just a sequence number in the list. It cannot be saved when re-sorting.

Option 1:
Save values ​​to RadioGroup1.Items.AddObject('Мадрид', TObject(3)); and accordingly get your value from an Integer(RadioGroup1.Items.Objects[RadioGroup1.ItemIndex]) object Integer(RadioGroup1.Items.Objects[RadioGroup1.ItemIndex])

Option 2:
Store data separately, and use RadioGroup1 only to display it. When user actions with RadioGroup1, save changes to the data, and when data changes (for example, re-sorting), dynamically rebuild RadioGroup1.