How to get text from a cell in the ListBox?

Hi,

It has been long time since I worked with the ListBox. I forgot how to get a text from the cell in a ListBox.

I will need to create the following functionality

Scrolling through the fields in the ListBox will be switching pages in the PagePanel.

Very simple.

Thank you in advance,

Val

I would start by looking at the events and properties of the Listbox. http://documentation.xojo.com/index.php/Listbox

Thank you for the advice - I found my old project with the code there.


  Dim a1,a2,a3,a4,a5,a6,a7,a8,a9,a10 As String
  
  a1=ListBox1.Cell(0,0)
  a2=ListBox1.cell(1,0)
  a3=ListBox1.cell(2,0)
  a4=ListBox1.cell(3,0)
  a5=ListBox1.cell(4,0)
  a6=ListBox1.cell(5,0)
  a7=ListBox1.cell(6,0)
  a8=ListBox1.cell(7,0)
  a9=ListBox1.cell(8,0)
  a10=ListBox1.cell(9,0)
  
  
  if ListBox1.text=a1 then
    PagePanel1.Value=1
  elseif ListBox1.text=a2 then
    PagePanel1.Value=2
  elseif ListBox1.text=a3 then
    PagePanel1.Value=3
  elseif ListBox1.text=a4 then
    PagePanel1.Value=4
  elseif ListBox1.text=a5 then
    PagePanel1.Value=5
  elseif ListBox1.text=a6 then
    PagePanel1.Value=6
  elseif ListBox1.text=a7 then
    PagePanel1.Value=7
  elseif ListBox1.text=a8 then
    PagePanel1.Value=8
  elseif ListBox1.text=a9 then
    PagePanel1.Value=9
  elseif ListBox1.text=a10 then
    PagePanel1.Value=10
  end if

One thing is left to figure out - how to count the number of rows in the ListBox (it will be dynamically populated) and create a corresponding number string variables with the corresponding number of “If … then” statements.

I am pretty sure it must be done through the arrays and looping but I have to figure out the code.

I would appreciate any help with this regard.

Thank you,

Val

Ok, got to the ListBox1.ListCount property. Working on how to create a ListCount + 1 number of string properties.

Thank you,

Val

What about simply

PagePanel1.Value = Listbox1.ListIndex+1

Listbox1.Text is the cell value of the row Listbox1.ListIndex. ListIndex is zero-based, so you have to add 1.

Tim, you made me laugh because your one line code simply worked!

You are a genius!

Thank you very much for your help.

Val

Tim, on the second thought, that code will not work for me.

In my case the PagePanel will have a large number of the pages.

The CheckList will be dynamically populated. When the row is changed, the value of the row should be obtained, and then the PagePanel should be set to the corresponding page.

It is a little more complicated. If I had a static CheckList, your code would work perfectly.

Again, thank you for your help. I will remember your little piece of wisdom for my future references.

Thank you, again,

Val