how to fill listview without image

M

mrmagoo

I'm trying to fill a listview with data. I'm using the example from the help
file, but how do I modify this to avoid using images? I want the exact same
layout but without images. This procedure seems so dependent on the image
being the "anchor" of each row that I don't understand how to modify it.

Thanks.


Dim lv As ListView
lv = Me.ListView1
With lv
.View = View.Details
.LabelEdit = True
.AllowColumnReorder = True
.CheckBoxes = False
.FullRowSelect = True
.GridLines = True
.Sorting = SortOrder.Ascending
End With
Dim item1 As New ListViewItem("item1", 0)
With item1
.Checked = True
.SubItems.Add("1")
.SubItems.Add("2")
.SubItems.Add("3")
End With
Dim item2 As New ListViewItem("item2", 1)
With item2
.Checked = True
.SubItems.Add("4")
.SubItems.Add("5")
.SubItems.Add("6")
End With
Dim item3 As New ListViewItem("item3", 0)
With item3
.Checked = True
.SubItems.Add("7")
.SubItems.Add("8")
.SubItems.Add("9")
End With
Dim item4 As New ListViewItem("item4", 0)
With item4
.Checked = True
.SubItems.Add("7")
.SubItems.Add("8")
.SubItems.Add("9")
End With
With lv
.Columns.Add("Column 1", -2, HorizontalAlignment.Left)
.Columns.Add("Column 2", -2, HorizontalAlignment.Left)
.Columns.Add("Column 3", -2, HorizontalAlignment.Left)
.Columns.Add("Column 4", -2, HorizontalAlignment.Left)
.Items.AddRange(New ListViewItem() {item1, item2, item3, item4})
End With

Dim imageListSmall As New ImageList
Dim imageListLarge As New ImageList

' Initialize the ImageList objects with bitmaps.

imageListSmall.Images.Add(Bitmap.FromFile("D:\Data\MySmallImage1.bmp"))

imageListSmall.Images.Add(Bitmap.FromFile("D:\Data\MySmallImage2.bmp"))

imageListLarge.Images.Add(Bitmap.FromFile("D:\Data\MyLargeImage1.bmp"))

imageListLarge.Images.Add(Bitmap.FromFile("D:\Data\MyLargeImage2.bmp"))

''Assign the ImageList objects to the ListView.
lv.LargeImageList = imageListLarge
lv.SmallImageList = imageListSmall
Me.Controls.Add(lv)
 
G

Guest

mrmagoo,

The problem is the code that creates the columns, lines like this:

..Columns.Add("Column 1", -2, HorizontalAlignment.Left)

You need to change the negative number to a positive number representing a
column width.

You can just leave all the image stuff out, that's not the problem.

Kerry Moorman
 
M

mrmagoo

Beautiful. Thanks.


Kerry Moorman said:
mrmagoo,

The problem is the code that creates the columns, lines like this:

.Columns.Add("Column 1", -2, HorizontalAlignment.Left)

You need to change the negative number to a positive number representing a
column width.

You can just leave all the image stuff out, that's not the problem.

Kerry Moorman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top