weeurey weeurey - 7 months ago 23
Vb.net Question

How exactly do I create a multicolumn listbox in Visual Basic?

What I'm looking for is a list box that has multiple columns for example a list box for books where each row would have a title, price, author.

Bonus points for anyone who can give me some pointers on how exactly I can add items to the list aswell. Im guessing

listBox1.Items.Add("Harry Potter", "JK Rowling", 5.99);

wont work?

Answer

I've run into the same question before and turned to ListViews instead. Something like:

Public Class Form1
Public Sub New()

    ' This call is required by the designer.
    InitializeComponent()

    ' Add any initialization after the InitializeComponent() call.
    Dim lv As New ListView
    With lv
        .View = View.Details
        .FullRowSelect = True
        .Columns.Add("Title")
        .Columns.Add("Author")
        .Columns.Add("Price")
    End With

    Me.Controls.Add(lv)
    lv.Dock = DockStyle.Fill

    lv.Items.Add(New ListViewItem({"Harry Potter", "J.K. Rowling", 5.99}))
End Sub
End Class