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

ItemContainerGenerator.ContainerFromItem Returns null

3 Answers 620 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Vamshi
Top achievements
Rank 1
Vamshi asked on 27 Mar 2012, 10:27 PM
Hi,

I have a gridview that is bound to a list of my business objects. I am using the following line of code to get each row of the gridview that pertains to each of the bound business object.

var

 

 

row = this.rgvFlightsTargeting.ItemContainerGenerator.ContainerFromItem(currFlight) as Telerik.Windows.Controls.GridView.GridViewRow;

where 'currFlight' is one object and 'rgvFlightsTargeting' is my gridview. Now if I group this gridview by a column, the above line of code will sometimes return a null (staring with the first time, I suppose because of the group header row). How do I handle this issue?

I am new to telerik controls so still trying to find my way around.

Thanks in advance!

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 28 Mar 2012, 06:58 AM
Hi,

 Why not work with the grid Items collection instead UI elements? Working directly with the UI containers in both Silverlight and WPF is not recommended.  

Regards,
Vlad
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Vamshi
Top achievements
Rank 1
answered on 28 Mar 2012, 03:05 PM
Vlad,

I do work with the grid items collection, but at some stages in the application I need to see which rows in the grid the user has selected. That is mostly when I am using this approach. A more detailed code is, where 'rgvFlightsGeneral' is my gridview, 'DEExtenderDataServiceRef' is my WCF service, 'Flight' is my business object, a collection of which is bound to the gridview:

 

foreach (DEExtenderDataServiceRef.Flight currFlight in rgvFlightsGeneral.Items)
{
 var row = this.rgvFlightsTargeting.ItemContainerGenerator.ContainerFromItem(currFlight) as Telerik.Windows.Controls.GridView.GridViewRow;

 if (row.IsSelected)
 {
  // Here is where I perform my logic
 
 }
}

Also, based on your last reply, should I not be accessing the UI elements in any case at all? How do I access values from, for example, a combobox in a CellEditTemplate?

Thanks!

0
Vamshi
Top achievements
Rank 1
answered on 28 Mar 2012, 04:47 PM
Duh.....I got it. I didn't earlier see the 'SelectedItems' property of the gridview. This working for us now.

Thanks!

Tags
GridView
Asked by
Vamshi
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Vamshi
Top achievements
Rank 1
Share this question
or