Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2012-04-08
3
Medium Priority
?
1,663 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Screencast - Getting to Know the Pipeline

610 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