happyD
happyD

Reputation: 146

Listview two items per row vb.net

I'm using vb.net 3.5 and making the UI in VB forms.

I intend to upgrade our tech but in the meantime, how would I display two items per row using a Listview?

In other words, I don't want two columns for one item:

Item id   Item value
--------------------
Item 1    Value 1
Item 2    Value 2

But really two items spanning two columns:

Item 1     Item 3
Item 2     Item 4

Thanks

Upvotes: 0

Views: 1464

Answers (1)

Blackwood
Blackwood

Reputation: 4534

If your items has subitems, you can only show the subitems with ListView.View set to View.Details which will always use one row for each item. Otherwise you can use one of the other ListView.View options. Here is an example using View.Tile that sizes the tiles so that two will fit in a row.

Dim lv As New ListView
lv.Location = New Point(10, 100) 'Pick a location and size that will fit in your form
lv.Size = New Size(100, 100)
lv.View = View.Tile
lv.TileSize = New Size(45, 20)
lv.Items.Add(New ListViewItem("Item 1"))
lv.Items.Add(New ListViewItem("Item 2"))
lv.Items.Add(New ListViewItem("Item 3"))
lv.Items.Add(New ListViewItem("Item 4"))
Me.Controls.Add(lv)

Obviously, you could use the forms designer to create the ListView. I have created it in code here so that all the information is in one place.

Upvotes: 1

Related Questions