Hey I'm trying to add information to a listbox, but when i try this code it doesn't display it properly.

Dim fmtstr As String = "{0,-10}{1,12}{2,14}"
With lstservices.Items
.Clear()
.Add(String.Format(fmtstr, "Room Rentals", "Half-Day", "Full-Day"))
.Add(String.Format(fmtstr, "1. Standard Rooming", "$32.00", "$65.00"))
.Add(String.Format(fmtstr, "2. Deluxe Rooming", "$72.00", "$144.00"))
End With

I want the results to show under each of the proper category, not all over the place.

Recommended Answers

All 2 Replies

You will need to add the extra spaces to make up the gaps

Dim fmtstr As String = "{0,-10}{1,12}{2,14}"
With lstservices.Items
    .Clear()
    .Add(String.Format(fmtstr, "Room Rentals        ", "Half-Day ", "Full-Day"))
    .Add(String.Format(fmtstr, "1. Standard Rooming ", "$32.00   ", "$65.00"))
    .Add(String.Format(fmtstr, "2. Deluxe Rooming   ", "$72.00   ", "$144.00"))
End With

and change the font to "Courier New" as the letter 'i' and 'O' use the same amount of space in this font

commented: Really Helpful, and clear. +1

Thanks ptaylor965. I got it fixed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.