Solved

converting gridview to listview

Posted on 2008-10-23
2
899 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
Comment Utility
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
Comment Utility
cool, thanks very useful

i also amended my for each to get ListViewDataItem

foreach (ListViewDataItem item in BasketListView.Items)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

12 Experts available now in Live!

Get 1:1 Help Now