Welcome to the Xceed Community Sign in | Join | Help
Community Search  

GetContainerFromItem method returns null

Sort Posts: Previous Next
  •  05-14-2008, 5:11 PM Post no. 12275

    GetContainerFromItem method returns null

    Hi,

    After setting a data grid control's items source, I want to access the data row for each item I've added. There are more columns in the grid than properties on the item, and I would like to set their values. After reading the documentation, I tried the GetContainerFromItem method, but it returns null.  My code looks like (with names simplified):

    datagrid.ItemsSource = serviceCallResult[];

    DataRow row; 

     foreach (item in datagrid.ItemsSource as serviceCallResult[])

    {

        row = datagrid.GetItemFromContainer(item) as DataRow;

        ... 

    }

     The documentation said that every item in the grid has a container so this seems very odd, and my guess is that I made a mistake in providing data to the grid. Also, I did try to call the GetItemFromContainer method without the cast and just assign the result to a DependencyObject, and it was also null. Thanks in advance for any help.

     

  •  05-14-2008, 5:29 PM Post no. 12277 in reply to 12275

    Re: GetContainerFromItem method returns null

    Only the items that are visible in the viewport have containers, so if you calling GetContainerFromItem on an item that is in the current context but does not have a container, null will be returned (this was not clear in the documentation, I will add this information).

    For what reason do you need to access all the containers? Maybe there is another solution to your scenario. 


    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
  •  05-15-2008, 11:11 AM Post no. 12306 in reply to 12277

    Re: GetContainerFromItem method returns null

    The reason for accessing the containers is that I would like to provide additional information in the grid that is not stored in the database (like a description field for a flag). My idea was to add columns to the the grid, and after the items source is set, to populate those additional fields by accessing the Cells array in the DataRow.
  •  05-16-2008, 8:13 AM Post no. 12324 in reply to 12306

    Re: GetContainerFromItem method returns null

    If the fields are also present (albeit empty) in the data source, then  you could access the data item directly to feed the missing data rather than using the container.
    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
  •  10-03-2008, 4:28 AM Post no. 15864 in reply to 12324

    Re: GetContainerFromItem method returns null

    Dear Xceed Team,

     

    Any update on this?

     

     

    I am trying to loop through all the data rows within the grid and set their visibility, but couldn't access all the data rows within the grid.

     

    Is there any way to do this ?

     

    Kr. 

  •  10-03-2008, 8:22 AM Post no. 15873 in reply to 15864

    Re: GetContainerFromItem method returns null

    Only the data items that are in the viewport have containers (i.e., DataRows). It will not be possible to loop through them all to set their visibility. You could create a style that sets it though.
    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.