Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP - ListView in Details View - Add image to column, or change font

Status
Not open for further replies.

MissouriTiger

Programmer
Oct 10, 2000
185
US
I hope someone can point me in the right direction. I just started a new job and have taken over a VB.Net desktop project that was started by someone who left. This is my first .Net project, but I have worked with VB 6 a little bit in the past.

The program uses a ListView in "Details View" to dsplay items in a shopping cart (this is a kiosk, not a website). The last column is a "Delete" column (the rightmost column), and the cell in each row will (hopefully) contain an image to click on to delete that item from the shopping cart. We might be able to settle for a Red "X" in text instead of an image, but an image is preferable.

I have not been able to find a way to add an image to the column cells, nor have I found a way to change the font color or style in that column.

Is it possible to do any of these things? Where can I find documentation explaining how?

Is there another VB control that is more appropriate for doing this kind of thing?

Any advice/information would be greatly appreciated.



Greg Norris
Software Developer & all around swell guy


__________________________________________________
Constructed from 100% recycled electrons.
 
This is straight from the help file. (Look under ListViewItem)

Code:
Private Sub CreateMyListView()
        ' Create a new ListView control.
        Dim listView1 As New ListView
        listView1.Bounds = New Rectangle(New Point(10, 10), New Size(300, 200))

        ' Set the view to show details.
        listView1.View = View.Details
        ' Allow the user to edit item text.
        listView1.LabelEdit = True
        ' Allow the user to rearrange columns.
        listView1.AllowColumnReorder = True
        ' Display check boxes.
        listView1.CheckBoxes = True
        ' Select the item and subitems when selection is made.
        listView1.FullRowSelect = True
        ' Display grid lines.
        listView1.GridLines = True
        ' Sort the items in the list in ascending order.
        listView1.Sorting = SortOrder.Ascending

        ' Create three items and three sets of subitems for each item.
        Dim item1 As New ListViewItem("item1", 0)
        ' Place a check mark next to the item.
        item1.Checked = True
        item1.SubItems.Add("1")
        item1.SubItems.Add("2")
        item1.SubItems.Add("3")
        Dim item2 As New ListViewItem("item2", 1)
        item2.SubItems.Add("4")
        item2.SubItems.Add("5")
        item2.SubItems.Add("6")
        Dim item3 As New ListViewItem("item3", 0)
        ' Place a check mark next to the item.
        item3.Checked = True
        item3.SubItems.Add("7")
        item3.SubItems.Add("8")
        item3.SubItems.Add("9")

        ' Create columns for the items and subitems.
        listView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left)
        listView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left)
        listView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left)
        listView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center)

        'Add the items to the ListView.
        listView1.Items.AddRange(New ListViewItem() {item1, item2, item3})

        ' Create two ImageList objects.
        Dim imageListSmall As New ImageList
        Dim imageListLarge As New ImageList

        ' Initialize the ImageList objects with bitmaps.
        imageListSmall.Images.Add(Bitmap.FromFile("C:\MySmallImage2.bmp"))
        imageListLarge.Images.Add(Bitmap.FromFile("C:\MyLargeImage2.bmp"))

        'Assign the ImageList objects to the ListView.
        listView1.LargeImageList = imageListLarge
        listView1.SmallImageList = imageListSmall

        ' Add the ListView to the control collection.
        Me.Controls.Add(listView1)
    End Sub

I hope this helps.



Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.
 
I appreciate the try, but I'm pretty sure this displays the images in the leftmost column, which won't do me any good. It looks like I'm going to have to go with checkboxes, and a button down below to do the deleting.





Greg Norris
Software Developer & all around swell guy


__________________________________________________
Constructed from 100% recycled electrons.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top