reading data from single column weblistbox

I am experimenting with the weblist box controller and the mapviewer control in XOJO. Trying to decide if I want to upgrade from release 2012.r2 enterprise.

I am trying to read a pre filled list box with sample addresses and then add location to the map viewer. I keep getting an error that the item does not exist when I put the following code in the action event on a web button

dim location as new WebMapLocation

//location.address = TextField1.Text

dim i as Integer
for i = 0 to listbox1.listcount -1 //< this is the line that the error shows up is there something different with the web list box. I cannot find the listcount method in the language reference. is this still supported.

if i = 0 then
  textfield1.text = str(listbox1.cell(listbox1.listindex,0))
  location.address = TextField1.Text
  Mapviewer1.AddLocation(location)  // adda pin to map 
end if

next

so I found out that Listcount is really rowcount
So that fixed my first problem, now I am getting an out of bounds error trying to load the contents of the listbox1 to a textfield1

dim location as new WebMapLocation

//location.address = TextField1.Text

dim i as Integer
for i = 0 to listbox1.rowcount -1
if i = 0 then
textfield1.text = str(listbox1.cell(listbox1.listindex,0)) // out of bounds error not sure why…list box has 4 rows and is only one column
location.address = TextField1.Text
Mapviewer1.AddLocation(location) // add a pin to map
end if
next


Thank you,
Cory

What is listindex at this point? If you have no row selected it will be -1.

Tim’s right in your code you are trying to assign text to a textbox that doesn’t exist yet because as you don’t have a row selected when the code is called.

So a fix for that is to check if you do have a row selected… just throw in a line of code to check

if listbox1.listindex>-1 then // do the work.

thanks, I will look into it… I will check it out.

Ok thanks for the info, I added a line to say of code to add to show that (i) is selected and a line to check to see if listbox is -1.

I have also added through the control for items in the list box so the row count of 3 (I think). The list box is a single column and no header
the check for listbox being greater than -1 doesn’t recognize the items in the control.
(environment is
a) XOJO 4.1
b) web page
c) push button
d) Mapviewer
e) listbox
The code below is in the push button action method.
I know this is simple but, I am not seeing it…

dim location as new WebMapLocation
dim i as Integer
if listbox1.listindex>-1 then

for i = 0 to listbox1.rowcount -1
  listbox1.Selected(i)=true
  //for i = 0 to listbox1.listcount -1
  if i = 0 then
    textfield1.text = str(listbox1.cell(listbox1.listindex,-1))
    location.address = TextField1.Text
    Mapviewer1.AddLocation(location)  // adda pin to map 
  end if
next

else
msgbox “Hot dog”
end if

Given that code, you should see the textfield holding the value of the selected row only. Is that what you see? Is it what you intended? Please tell us what you expect to see and what you actually do see. It will be much more helpful than just throwing code on the screen. I can tell you that this code looks weird, but that doesn’t help unless I know what you really intended to happen.

I see that, What I had originally wanted was the ability to loop through the listbox row by row and populate the map viewer. with one click.

Why are you using ListIndex, then? If you want the contents of the current row inside your loop use

location = New WebMapLocation
location.address = listbox1.Cell(i, 0)
Mapviewer1.AddLocation(location)

Note that you should create a new WebMapLocation object for each point you want to add.