Home / comp / gb.qt / listbox / list 
ListBox.List (gb.qt)
Syntax
PROPERTY List AS String[]
Returns or sets the ListBox contents from a string array.

This example shows how you can save and reload the content of a Listbox to a text file. When opening the file we use the Split method so each line becomes on item in the Listbox. When saving the file we use the string[].Join method to create a single string with each list item on a line.

Examples

' Open a text file for display in the ListBox
PUBLIC SUB ButtonOpen_Click()
  Dialog.Filter = ["*.lst", "Lists", "*.txt", "Text Files", "*", "All Files"]
  IF Dialog.OpenFile() THEN RETURN
  ListBoxItems.List = Split(File.Load(Dialog.Path), "\\n")
CATCH
  Message.Info("Cannot load list:\\n" & Dialog.Path & "\\n" & Error.Text)
END

' Save the ListBox content to a text file
PUBLIC SUB ButtonSave_Click()
  Dialog.Filter = ["*.lst", "Lists", "*.txt", "Text Files", "*", "All Files"]
  IF Dialog.SaveFile() THEN RETURN
  File.Save(Dialog.Path, ListBoxItems.List.Join("\\n"))
CATCH
  Message.Info("Cannot save list:\\n" & Dialog.Path & "\\n" & Error.Text)
END

Note that that there is at least one defect with this example. If any item strings in the Listbox contain new lines than they will be split into two lines. Maybe not what you want.