item in Listbox

I'm trying to figure out what I'm missing here in this piece of code:
dim s as string =""
for each item In me.listbox1.items
s=s & item.tostring & vbcrlf
...
i get this error msg: "Name 'item' is not declared"
Any help would be appreciated.
aLEX
[305 byte] By [xanxa5] at [2007-12-24]
# 1

Hi,

try changing the following code line [assuming your listbox is filled with string items]:

For Each item As String In Me.listbox1.Items
...

Andrej

AndrejTozon at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2
Thanks. That did solve the problem.
xanxa5 at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3
I'm affraid it didn't solve my problem after all.
here's the code I'm trying to write:
Dim s As String=""
For Each item In ListBox1.Items
s=S & item.tostring
Next
Someone posted it for me previously.
As I said before, 'Item' is not declared.
adding 'As String' as you mentioned causes the following error message to appear when I run the application:
"converting 'dataRowView' type to 'String' type is not valid" (I'm translating here).

My listbox is filled with strings.
please, help
thanks

xanxa5 at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4

According to your error message, the list items are of DataRowView type, not string - you're probably binding to a datatable. Try this:

For Each item As DataRowView In ListBox1.Items
Dim itemText As String = item(ListBox1.DisplayMember).ToString()
...

The reason for "'Item' undeclared" message is that you didn't declare your item variable (in the for each statement) as the same type you're using to fill the listbox.

Andrej

AndrejTozon at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 5
Thanks Andrej. Now it's working fine.
xanxa5 at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...