Home All Groups Group Topic Archive Search About

how to fill listview without image

Author
27 Apr 2006 7:59 AM
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)

Author
27 Apr 2006 11:41 AM
Kerry Moorman
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


Show quoteHide quote
"mrmagoo" wrote:

> 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)
>
>
>
Author
27 Apr 2006 2:51 PM
mrmagoo
Beautiful. Thanks.


Show quoteHide quote
"Kerry Moorman" <KerryMoor***@discussions.microsoft.com> wrote in message
news:FEF4C01D-7494-4EB4-A5E1-D07C4FC24F31@microsoft.com...
> 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
>
>
> "mrmagoo" wrote:
>
> > 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)
> >
> >
> >