listbox confusion

Post

Posted
Rating:
#1 (In Topic #535)
Trainee
 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
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Regular
stevedee is in the usergroup ‘Regular’

carlhood said

…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:-

Code (gambas)

  1. 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:-

Code (gambas)

  1. Public Sub ListBox1_Click()
  2.  
  3.     Me.Text = ListBox1.Text
  4.  
Online now: No Back to the top

Post

Posted
Rating:
#3
Guru
BruceSteers is in the usergroup ‘Guru’
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
Online now: No Back to the top

Post

Posted
Rating:
#4
Trainee
 Thank you very much! Just what I needed.
Your help was greatly appreciated

Carl
Online now: No Back to the top
1 guest and 0 members have just viewed this.