Solved

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

Posted on 2012-04-08
3
1,406 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
Comment Utility
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
Comment Utility
0
 
LVL 20

Assisted Solution

by:BuggyCoder
BuggyCoder earned 100 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

13 Experts available now in Live!

Get 1:1 Help Now