Wednesday, June 17, 2009

VB.NET ListView Tutorial. Add, Edit and Delete

One of my most commonly used VB.NET control to present a spread-sheet like information is the ListView control. According to msdn, a list-view control is a window that displays a collection of items using one of four different views. List-view controls provide several ways to arrange and display items and are much more flexible than simple List Boxes. On this article, I will discuss the basics of adding, editing and deleting items in listview. A complete sample project can be downloaded at the end of this post.

At the end of the tutorial, you will be able to do the following tasks:1. Properly configure ListView to display spread-sheet information2. Add Items on ListView3. Edit Item on ListView4. Delete Item on ListView

Here are the step-by-step to create our list view tutorial project.1. Create a new project in VB.NET2. Put the following controls as shown below on your initial form

3. Set the ListView control and set the following properties from the Property window.a. FullRowSelect = Trueb. GridLines = Truec. HideSelection = Falsed. MultiSelect = Falsee. View = Details

4. Declare blnAdd variable that will indicate if Add button was pressed.

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click If ListView1.SelectedItems.Count > 0 AndAlso MessageBox.Show("Do you want to delete this item?", "Confirm", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then 'make sure there is a selected item to delete ListView1.SelectedItems(0).Remove() End If End Sub

8. To select an item and put the values on the respective textboxes, use the following codes:

i'm still confused coz this is what i wanted to happen oK??i create a system in vb.net its a simple student registration ok..then i have 2 forms 1st contains a listview and the ADD,EDIT,DELETE buttons...the 2nd form contains the fields that i wanted to be fill up by the user..this is want i want to happen when i click btnADD appears the 2nd form then fill up fields and then added to the 1st form which contains the listview..and of course it has a database wherein data is stored..please help i need it on my project

Everything worked great but none of the names I add to the Listview stays there after closing the application. There doesn't seem to be any code to create a XML file to store the saved names on the listview. Help!

If my 1st listview is in form1.vb then my 2nd listview is in form2.vb what will be the code or syntax if my items in 1st listview in form1.vb is the same with the items in 2nd listview in form2.vb... and must update the data's....

I'm doing a program in C#, wherein after populating a treeview from an XML file, I should double click a node that corresponds as a subnode or childnode, and display in a search result box. after double clicking the node, it application(processes) must run as where that xml file corresponds..thank you a lot..

I NEED YOUR HELPWhat if I want to have many columns? I made a Contacts project. It has many SubItems like Address, Email, Mobile no., fb, twitter. How do I modify your codes? It doesn't work :(( please help me.

hi, how if i want to display the data but there empty data for one of the data such as i don't have last name. i wish to just display first name and the last name is empty? I've no idea how to do so. It turn up error if the data is empty in database.

Hi, how can i display a data where there is empty data for example i wish to display only first name and in my database lastname is empty, i just want to display firstname and lastname is empty. how can i do so? i've no idea how is it. Thx in advance.