?
Solved

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

Posted on 2012-04-08
3
Medium Priority
?
1,604 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 400 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 1200 total points
ID: 37820985
0
 
LVL 20

Assisted Solution

by:BuggyCoder
BuggyCoder earned 400 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

765 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