ItemContainerGenerator.ContainerFromItem Returns null

4 posts, 0 answers
  1. Vamshi
    Vamshi avatar
    17 posts
    Member since:
    Jul 2010

    Posted 27 Mar 2012 Link to this post

    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!

  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 28 Mar 2012 Link to this post

    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 >>
  3. Vamshi
    Vamshi avatar
    17 posts
    Member since:
    Jul 2010

    Posted 28 Mar 2012 Link to this post

    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!

  4. Vamshi
    Vamshi avatar
    17 posts
    Member since:
    Jul 2010

    Posted 28 Mar 2012 Link to this post

    Duh.....I got it. I didn't earlier see the 'SelectedItems' property of the gridview. This working for us now.

    Thanks!

Back to Top