?
Solved

converting gridview to listview

Posted on 2008-10-23
2
Medium Priority
?
966 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
[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
2 Comments
 
LVL 15

Accepted Solution

by:
NazoUK earned 2000 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

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

800 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