How do I edit a listview on visual basic?

Written by laura gittins
  • Share
  • Tweet
  • Share
  • Email

In Visual Basic, the ListView control displays items in a collection. After adding the ListView item to your project, you can write functions to allow the user to edit items already in the list, insert new items to the list or take them out. You use the "Add" and "Remove" methods to perform these actions on list items, but Visual Basic allows you a lot of flexibility in how you implement these methods. One way is to call these methods when a user clicks a button.

Skill level:
Moderately Easy

Other People Are Reading


  1. 1

    Open your project's code window and add the following lines to the "Form_Load" function, or another function you call when your ListView control is activated:

    ListView1.View = View.Details

    ListView1.LabelEdit = True

    ListView1.AllowColumnReorder = True

    ListView1.GridLines = True

    The View.Details function displays the ListView items. The LabelEdit function lets you edit text items in the ListView. AllowColumnReorder lets you rearrange the order of columns. GridLines displays a grid behind the ListView items, making them easier to see, especially when many items are in the list.

  2. 2

    Open the "Design" editor. Double-click the "Button" control in the toolbox to add one to the form. Change the "text" property to "Add Item." Add a second button to the form, and change its "text" property to "Remove Item."

  3. 3

    Open the "Add Item" button's "click" sub and type the following lines:

    Dim item As New ListViewItem("Name")

    item.SubItems.Add("More data")


    The first line declares a new item to add to the ListView and enters "Name" into the first column. You can change this parameter to any other strings, including strings entered into TextBoxes. The second line contains data for the second column in the ListView. If your ListView has more columns, use an additional "item.SubItems.Add" for each one. The third line adds the item to the ListView list and displays it.

  4. 4

    Open the "Remove Item" button's "click" sub and type the following line:


    The "Remove" function removes an item from the ListView and takes a ListView item as a parameter. The parameter itself specifies the ListView item at index zero, otherwise the first item in the list, and removes it. You may write code to specify different items to remove, but make sure you include error handling in case the user tries to remove an item at an out-of-bounds index.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.