Listview Add, Remove, Edit Sub Items

Posted on 2006-05-26
Last Modified: 2008-02-01
Username       Age      Hair Color
Jack               20        Black
Jane               28        Brown

ListView1.Items("jack").subitem("age").text = "20"
ListView1.Items("jack").subitem("hair color").text = "Black"

ListView1.Items("jessica").subitem("age").text = "28"
ListView1.Items("jessica").subitem("hair color").text = "Brown"

How can I use the listview item above for basic functionality?  This control seems so difficult to use. Can you translate the code into the proper use? I know i'm not using these items correctly. Please Help
Question by:Hepen
    LVL 9

    Accepted Solution

    Hi Hepen,

    The ListView Control consistes of a collection lf ListViewItem, and each ListViewItem consist of SubItems. first, Items and subitems must be instantiated before they can be used. This are regular objects. Then, you address all of them by the index and not by content. Below see an example. It is a copy of the integrated help of the ListViewItem class.
    It is always a good idea to consult the integrated help (F1). It shows the fundamentals of how to program a ListView

    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
        Dim item2 As New ListViewItem("item2", 1)
        Dim item3 As New ListViewItem("item3", 0)
        ' Place a check mark next to the item.
        item3.Checked = True

        ' 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.

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

        ' Add the ListView to the control collection.
    End Sub 'CreateMyListView


    Author Comment

    oh my god your kidding me.

    is there any other form control that will give me the above functionality or similar that i was looking for? I'm not looking to code a C++ application. LOL
    LVL 3

    Expert Comment


    There are hundreds of third party grid/listview controls on the web Try Xceed .Grid control

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now