numbers before listbox items

ud2008

Well-known member
Joined
Jul 5, 2010
Messages
148
Programming Experience
Beginner
At the moment I have a listbox which contains several items.

On a button I want to "export" those items, add a number for each item.

I can see the numbers but the items are displayed as: system.string[].

1 system.string[]
2 system.string[]
3 system.string[]

What do I do wrong:
VB.NET:
Dim Larray As New ArrayList(ListBox1.Items)
        Dim i() As String
        i = DirectCast(Larray.ToArray(GetType(String)), String())
        Dim s As Integer
        For s = 0 To ListBox1.Items.Count - 1
            printsonglist.SourceText &= s + 1 & i.ToString & vbNewLine
        Next

Thanks
 
printsonglist.SourceText &= s + 1 & ListBox1.Items(s).ToString & vbNewLine
 
Thanks that works, I do have one small thing.

I try to add : just after the number, but get a message: Conversion from string ": " to type 'Double' is not valid.
 
Thanks that works, I do have one small thing.

I try to add : just after the number, but get a message: Conversion from string ": " to type 'Double' is not valid.

If you are adding a number to a string then you could be getting an error so whenever I have to concatenate numbers and strings I always add the number by doing this for instance:

Dim TestNum as Integer
Dim TestString as String = "Test Number = "

TestNum = 2
TestString += TestNum.ToString

This then converts the number to a string format and stops any erors of this type.
 
Using + operator to add strings is all well if you make sure both operands are strings, but it is better to use the dedicated string concatenation operator & (and also &= operator).
 
Using + operator to add strings is all well if you make sure both operands are strings, but it is better to use the dedicated string concatenation operator & (and also &= operator).

Thanks again, that worked, I thought I tried that already, but it works.

Problem solved.
 
Back
Top