VBA- Printing to a listbox

I'm writing a piece of code in VBA that imports some data, organizes it, and then prints it out in a list box. But i can't figure out what i'm doing wrong when trying to print to the list box. My code looks like this.

Private Sub cmdDisplaySchedule_Click()
    Call listSchedule
End Sub

Public Sub listSchedule()

Dim i As Long

    For i = 1 To MB2Boats.Count 'MB2Boats is the class where all of my data is containted.

        SchedulerUserForm.LBoxBay2.AddItem
        SchedulerUserForm.LBoxBay2.List(i - 1, 0) = MB2Boats(i).MB2BoatName
        SchedulerUserForm.LBoxBay2.List(i - 1, 1) = MB2Boats(i).MB2Bay
        SchedulerUserForm.LBoxBay2.List(i - 1, 2) = MB2Boats(i).MB2Duration
        SchedulerUserForm.LBoxBay2.List(i - 1, 3) = MB2Boats(i).MB2Waiting
        SchedulerUserForm.LBoxBay2.List(i - 1, 4) = MB2Boats(i).MB2StandardDeviation
    Next i

End Sub

The above will only print the boatnames and nothing else. Any help is appreciated. Thanks!

Answers


Maybe all data is loaded into the form and you just don't see it yet. Try adding this line to the end of the sub:

SchedulerUserForm.LBoxBay2.ColumnCount = 5

As an update to the comments provided here is an interesting little example (with an empty workbook an empty new UserForm1 and and empty new ListBox1 dropped into the UserForm1:

Public Sub ListBoxColumnTest()

Load UserForm1

UserForm1.ListBox1.AddItem
UserForm1.ListBox1.List(0, 0) = "hello"
UserForm1.ListBox1.List(0, 1) = "hello"
UserForm1.ListBox1.List(0, 2) = "hello"
UserForm1.ListBox1.List(0, 3) = "hello"
UserForm1.ListBox1.List(0, 4) = "hello"

'The below message box will answer with 1
MsgBox "The current column count is: " & UserForm1.ListBox1.ColumnCount
'This will increase the column count to 5 and
'thereby only adjust the column widths (fair distribution of the give space for 5 even columns).
UserForm1.ListBox1.ColumnCount = 5

UserForm1.Show

End Sub

Need Your Help

WCF - Routing Issue

c# wcf rest routing

I am working on a WCF REST service, and in the service I have two methods with the same URITemplate. One of them is marked with a WebGet and the other with a WebInvoke using PUT as the method.

OpenGL texture mapping

opengl textures texture-mapping

I have two objects drawn on screen in openGL, one is a sphere using the GLU object and one is a texture mapped star. Regardless of the z coordinates, the texture mapped star always seems to draw in...