How to Walk through a Listbox.

Hi all!

How can I walk through a Listbox, I know theres ColumnCount to count the columns, If I do this, It Display the value of each cell in one row:

For i As Integer = 0 to lista.ListCount
Msgbox Cstr(lista.CellTag(lista.LastIndex, i))
Next

So I want to get the value of one cell and column to pass it to a class to report it on Excel.

regards

First, make sure to use listcount-1 so you don’t get an out of bounds exception.

This will give you the value of every cell, by row and column:

for i as integer=0 to lista.listcount-1 //this loops through all of the rows for j as integer=0 to lista.columncount-1 ///this loops through all of the columns for each row msgbox lista.cell(i,j) next next

For row As Integer = 0 to lista.ListCount-1
  For column as Integer = 0 to lista.ColumnCount-1
    Msgbox Cstr(lista.Cell(row, column))
  Next
Next

[quote=196499:@Tom Iwaniec]First, make sure to use listcount-1 so you don’t get an out of bounds exception.

This will give you the value of every cell, by row and column:

for i as integer=0 to lista.listcount-1 //this loops through all of the rows for j as integer=0 to lista.columncount-1 ///this loops through all of the columns for each row msgbox lista.cell(i,j) next next[/quote]
Perfect! Thanks