Author Topic: List Box  (Read 323 times)

0 Members and 1 Guest are viewing this topic.

Offline MLambert

  • Forum Regular
  • Posts: 113
List Box
« on: August 24, 2020, 09:14:04 PM »
Hi,

I am trying to do a list box … but I don’t understand how.

“You add items using the AddItem method. At design time you do so by changing the List Items property. To add multiple items, separate them using a new line escape sequence (\n).
At design time, you can set the Value property to have an item saved preselected.”
I am not sure .. do I add the items at design time or do I load them at run time ?
I cannot see any Value property on the design screen.
I could not find “AddItem” in the generated code.

MIke

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 672
  • If you're API and you know it clap your hands
    • My GitHub
Re: List Box
« Reply #1 on: August 25, 2020, 12:46:56 AM »
Quote
I could not find “AddItem” in the generated code.
AddItem isn't something generated automatically (technically it is but it isn't implemented automatically). AddItem is a SUB that is called in the BAS code to put a new item in the list box. In whatever event you like, use AddItem.


Quote
I am not sure .. do I add the items at design time or do I load them at run time ?
I prefer to add them at run time because I don't like having to edit the form in the editor just to add more stuff. I'd rather just have a list either stored somewhere in a file or read in data from some other external source and add my items then. It's personal preference but the simplest way is to add them at run time.


Quote
I cannot see any Value property on the design screen.
As for the value, you can obtain the value of the selected item following the instructions in Fellippe's Wiki:
Quote
At run time, you can read which item is currently selected by reading the Value property:
Code: QB64: [Select]
  1. theItem% = Control(ControlID).Value
  2. DesiredItem$ = GetItem$(ControlID, theItem%)

Whereas ControlID would be the name of whatever you named your list box.
« Last Edit: August 25, 2020, 12:54:16 AM by SpriggsySpriggs »

Offline MLambert

  • Forum Regular
  • Posts: 113
Re: List Box
« Reply #2 on: August 26, 2020, 01:46:58 AM »
Thank you