A tip for making "columns" in list boxes


New member
Feb 17, 2009
Edmonton, Alberta, Canada
Programming Experience
Hello all!

My name is Camron, and this is my first post on the VB.NET forums.

I joined the forums because I am using Visual Studio this semester in my school.

Anyway, I thought I would share a neat little trick with everyone for creating "columns" in a list box without having to use DataGrids. Now, there are some restrictions:

1. You must use monospaced fonts
2. These are not real columns, they only look like columns
3. You must have a maximum length of the different columns

However, they present information nicely within a list box, so here goes:

When you add a row to a ListBox, you can format the string you input by using the String.Format method. For example:

Dim ZoneFormat As String = "{0,-10}{1,-20}{2,-8}"
With CourseList.Items
.Add(String.Format(ZoneFormat, "Course ID", "Course Name","Hours"))
.Add(String.Format(ZoneFormat, "IST235", "Client Server Programming,"96"))
.Add(String.Format(ZoneFormat, " IST245", " Data Base Management","80"))
End With

Makes a well formatted little.

Thought I'd share this. Couldn't hurt anyone. If anyone sees an issue with this, or has something to add, please feel free! I love hearing about improvements and learning stuff

Top Bottom