I have a Listbox with 100-200 default values and the multiselect-simple mode is enabled.
I save the selected text items in a List of string:
Private Sub ListBox_Styles_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox_Styles.SelectedIndexChanged
Styles_List.Clear()
For Each item In ListBox_Styles.SelectedItems : Styles_List.Add(item) : Next
Save_INI_settings()
End Sub
After that the sub calls "Save_INI_settings" procedure then I save the values into a INI file like this:
WriteINIFile.WriteLine("Styles=" & String.Join(",", Styles_List.ToArray))
...Which produces this result:
Styles=Alternative,Electro,Pop,Rock
Now, in the next load of my application, how I can set the listbox selected items by picking the text values of the ini?
This is how I load my INI settings:
If ValueName = "Styles".ToLower Then
For Each Item In Value.split(",")
' ListBox_Styles.SetSelected(Item, True)
Next
End If
...Where "ValueName" var is "Styles" and "Value" var is "Alternative,Electro,Pop,Rock" so with the for i get this:
Alternative
Electro
Pop
Rock
PS: I don't want to save the index integers in the INI file instead the text items, also I don't want to store this settings in the app settings section.
UPDATE:
This is how I'm doing it right now:
If ValueName = "Styles".ToLower Then
For Each Item In Value.split(",")
' Try to add the string as is
ListBox_Styles.SelectedItems.Add(Item)
' Try to add the string as TitleCase
ListBox_Styles.SelectedItems.Add(Char.ToUpper(Item(0)) + StrConv(Item.Substring(1), VbStrConv.Lowercase))
' Try to add the string as WordCase
ListBox_Styles.SelectedItems.Add(System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(Item))
Next
End If
Works as expected, but too much iterations