Solved

VB.Net: Add, Edit, Delete values in ListView

Posted on 2012-04-08
3
1,457 Views
Last Modified: 2012-06-22
Hi Experts,

I am using ListView on my form, and it is filled with two columns of data.

I am very much familiar with datagridview, because i access cells' data in the datagridview by locating the row index and the column index.

But in the ListView, there isn't any commands or properties or methods such as rows or columns. Instead it has Items and subitems, and even by using it, it is very difficult for me to get values from the Listview.

I need to know how to access a particular cell value by its equivalent column and row of the listview.

Thanks in advance.
0
Comment
Question by:baabaa_nl
3 Comments
 
LVL 17

Assisted Solution

by:nepaluz
nepaluz earned 100 total points
ID: 37820978
There is an example on how to add editable items to a listview here
http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.aspx
0
 
LVL 17

Accepted Solution

by:
Anuroopsundd earned 300 total points
ID: 37820985
0
 
LVL 20

Assisted Solution

by:BuggyCoder
BuggyCoder earned 100 total points
ID: 37821011
if you just want to iterate over listview items then use this:-
foreach(var item in listView1.Items)
{
//Access each listviewdataitem and do your magic here
}

Open in new window


if you have some button in your listview, then use itemcommand event and handle it as:-
protected void EmployeesListView_OnItemCommand(object sender, ListViewCommandEventArgs e)
  {
    if (String.Equals(e.CommandName, "AddToList"))
    {
      // Verify that the employee ID is not already in the list. If not, add the
      // employee to the list.
      ListViewDataItem dataItem = (ListViewDataItem)e.Item;
      string employeeID = 
        EmployeesListView.DataKeys[dataItem.DisplayIndex].Value.ToString();

      if (SelectedEmployeesListBox.Items.FindByValue(employeeID) == null)
      {
        ListItem item = new ListItem(e.CommandArgument.ToString(), employeeID);
        SelectedEmployeesListBox.Items.Add(item);
      }
    }
  }

Open in new window


Reference:- http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.itemcommand.aspx

similarly there are other events that are available and you will be able to access the items through them also.
The links given above are good enough to help you find the other options/events....
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

803 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