This is a migrated thread and some comments may be shown as answers.

Loop thru radGridView

7 Answers 118 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Travis Gorrie
Top achievements
Rank 1
Travis Gorrie asked on 08 Mar 2011, 09:46 PM
How can I loop thru the grid? All forum examples uses .Rows; but I don't have that. I have radGridView.Items.

Thanks.

7 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 09 Mar 2011, 07:37 AM

Hello Travis Gorrie,

Well, that really depend on your scenario. If you would like to perform some action of the data that is displayed on the grid you could simply enumerate the Items collection which contains all data item that are displayed by the grid.

foreach (var item in grid.Items)
{
      
}



Regards,
Milan
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Travis Gorrie
Top achievements
Rank 1
answered on 10 Mar 2011, 03:26 PM

Milan,

Thanks for the reply.

I got to that point, but I want to read a column value. And I don't see how to do that using the var item.

 

I want to do something like this:

string name = item[6];

Thanks.

0
Maya
Telerik team
answered on 11 Mar 2011, 09:09 AM
Hello Travis Gorrie,

In case you want to get a particular value for an item, you may do the following:

foreach (var item in this.playersGrid.Items)
            {
                var name = (item as Player).Name;
            }

In example above the item is of type Player and has a property - Name. Thus you will be able to run through all the items and get each one's value in the Name column.
 

Best wishes,
Maya
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Travis Gorrie
Top achievements
Rank 1
answered on 11 Mar 2011, 02:11 PM
That's it. Thank you.
0
Julian
Top achievements
Rank 1
answered on 26 May 2011, 10:19 AM
Hello Maya,
Hello Travis,

that worked pretty good for me as well. Is there any (simple) possibility to (re-)set the fetched value (in your sample case 'name') inside the loop?

Best wishes,
Julian
0
Travis Gorrie
Top achievements
Rank 1
answered on 26 May 2011, 12:57 PM
Hi Julian,

Do you mean to set the Property value, like so:

foreach (var item in this.playersGrid.Items)
            {
                (item as Player).Name = "Julian";
            }
0
Julian
Top achievements
Rank 1
answered on 26 May 2011, 01:16 PM
Hey Travis,

yes, that was my first attempt too. Unfortunately it did not work the way i wanted...
If i debug it via Console.WriteLine in the code behind it shows the new value, but it is not updated in the Grid. You understand waht i mean? I'm not sure if there is any function to do kind of a "grid view update" on the specified cell...
Tags
GridView
Asked by
Travis Gorrie
Top achievements
Rank 1
Answers by
Milan
Telerik team
Travis Gorrie
Top achievements
Rank 1
Maya
Telerik team
Julian
Top achievements
Rank 1
Share this question
or