Solved

converting gridview to listview

Posted on 2008-10-23
2
918 Views
Last Modified: 2013-12-17
Hi all, i'm trying to convert a gridview into a listview.

The bit that is troubling me is that i can't get at item.DataRowIndex ( or the list view equivilent ) on the list view

int basketItemId = (int)BasketListView.DataKeys[item].Value;

any thoughts?
// This is the grid view version
 
  foreach (GridViewRow gridRow in BasketGrid.Rows)
        {
            if ((gridRow.RowType == DataControlRowType.DataRow))
            {
                int basketItemId = (int)BasketGrid.DataKeys[gridRow.DataItemIndex].Value;
                              
 
            }
        }
 
//  What i have of the listview version
 
   foreach (ListViewItem item in BasketListView.Items)
        {
            if ((item.ItemType == ListViewItemType.DataItem))
            {
                 int basketItemId = (int)BasketListView.DataKeys[item].Value;
 
 
            }
        }

Open in new window

0
Comment
Question by:frosty1
2 Comments
 
LVL 15

Accepted Solution

by:
NazoUK earned 500 total points
ID: 22794270
There are a couple of things you could do:

1: iterate through the items using a regular for loop instead a foreach:

for(int i=0; i<BasketListView.Items.Count;i++)
{
       ListViewItem item = BasketListView.Items[i];
       if (item.ItemType == ListViewItemType.DataItem)
            {
                 int basketItemId = (int)BasketListView.DataKeys[i].Value;
            }

}

2: Use IndexOf to find the index:
int basketItemId = (int)BasketListView.DataKeys[BasketListView.Items.IndexOf(item)].Value;
0
 

Author Comment

by:frosty1
ID: 22794886
cool, thanks very useful

i also amended my for each to get ListViewDataItem

foreach (ListViewDataItem item in BasketListView.Items)
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
daypilot scheduler 3 29
Web site error 3 41
imap mails 1 23
Call windows 10 virtual keyboard from windows forms app 2 36
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

810 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