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

Iterating Rows in rad gridView with custom added columns

3 Answers 130 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Evlo
Top achievements
Rank 1
Evlo asked on 13 Jun 2011, 11:48 PM
Hello,

I have entity framework classes, one is DownloadLink and i have these two columns to gird (not binded to any DownloadLink properties)

<telerik:GridViewColumn Header="New F.H.Id" UniqueName="NewFilehostId" Width="*"></telerik:GridViewColumn><telerik:GridViewColumn Header="New URL" UniqueName="NewUrl" Width="*"></telerik:GridViewColumn>

Only easy way to iterate row i found is using  radGridViewReuploadStatus.Items, but that way i can't access those two added columns.

So i think easiest way would be to somehow extend DownloadLink and add these two new fields, i tried it like this

class
 DownloadLinkExtended : DownloadLink {         public DownloadLinkExtended(DownloadLink origDl){             PropertyInfo[] myObjectProperties = origDl.GetType().GetProperties(); //BindingFlags.Public | BindingFlags.NonPublic             foreach (PropertyInfo pi in myObjectProperties)             {                 object value = pi.GetValue(origDl, null);                 if (value != null)                 {                     try                     {                         pi.SetValue(this, value, null);                     }                     catch (Exception) {                          //selze to na komplexnim typu jako napr. PostData                     }                 }             }         }         public string NewUrl { getset; }         public string NewIdOnFilehost { getset; }     }
But well that reflection does not work and i don't have it set up like DownloadLinkExtended.DownloadLink because then every grid bound column would need to be DownloadLink.field and i don't want it that way. Also setting it in constructor for each property individually is to much error prone manual work.

Other solution would be to get rows somehow like this
IList<GridViewRow> rows = radGridView.ChildrenOfType<GridViewRow>();
But since there is no .Rows this it seams to me that it is not your recommended way.

So what is ideal solution. Or how to nicely extend my DownloadLink class to include that two new required fields?

3 Answers, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 16 Jun 2011, 02:26 PM
Hello Evlo,

You may try utilizing the RadGridView.ItemContainerGenerator.ContainerFromIndex(int index) method to access the desired row and then iterate over its Cells collection, in order to read each of its cells.

Kind regards,
Ivan Ivanov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Evlo
Top achievements
Rank 1
answered on 16 Jun 2011, 02:29 PM
But it is no use with virtual rows. Anyway i opt to do it preferred way with modelview class as it is easiest in the end :(
0
Ivan Ivanov
Telerik team
answered on 20 Jun 2011, 10:05 AM
Hi Evlo,

Please, let me offer you another approach to your case. You may try utilizing GridViewBoundColumnBase's GetValueForItem method to access these cells' values. Please, let me know if this is a proper solution for your scenario. 

Greetings,
Ivan Ivanov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Evlo
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Evlo
Top achievements
Rank 1
Share this question
or