Solved

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

Posted on 2012-04-08
3
1,557 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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 (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

717 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