listbox confusion

Post your Gambas programming questions here.
Post Reply
carlhood
Posts: 3
Joined: Wednesday 30th December 2020 9:56am

listbox confusion

Post by carlhood »

Hi,
I am very new to Gambas, and respectfully request help on using a listbox. I have created a listbox and added several items. What I would like to do is select an item from the list and save the item in a string variable for use elsewhere in my program. I can retrieve the index number without problem, but can't load the actual string value of the item itself. I'm sure it must be simple, but I can't find any details how to do this.
Any help is greatly appreciated
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Re: listbox confusion

Post by stevedee »

carlhood wrote: Wednesday 30th December 2020 12:58pm ...What I would like to do is select an item from the list and save the item in a string variable...
I think you just need to use the .Text property, example:-
Me.Text = ListBox1.Text
..will return the selected item in the listbox (...and in this case display it as the Form's caption).

I hope this helps.

...Oh, and if you want to do this every time an item is selected:-
Public Sub ListBox1_Click()

    Me.Text = ListBox1.Text

End
User avatar
BruceSteers
Posts: 1565
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: listbox confusion

Post by BruceSteers »

Also Listbox1.List is a String[] array
So if you have the index you can do this...

sText = ListBox1.List[iIndex]

For sending text the other way from the variable to the list you have to make a new array.

ListBox1.List[iIndex] = sText ' This does not work

Dim aTemp As String[] = ListBox1.List.Copy()
aTemp[iIndex] = sText
ListBox1.List = aTemp

'That does work
If at first you don't succeed , try doing something differently.
BruceS
carlhood
Posts: 3
Joined: Wednesday 30th December 2020 9:56am

Re: listbox confusion

Post by carlhood »

Thank you very much! Just what I needed.
Your help was greatly appreciated

Carl
Post Reply