Refreshing self referencing grid causes error

6 posts, 1 answers
  1. Ed
    Ed avatar
    8 posts
    Member since:
    Apr 2010

    Posted 11 Feb 2013 Link to this post

    I have a grid that shows data that is self referencing.  The data is a simple List<> based collection of objects that have an Id and ParentId properties (among others).  [Using Telerik.WinControls.UI.RadGridView version 2012.3.1211.40]

    Below is the error information:

    Object reference not set to an instance of an object.
     
    GridViewCellInfoCollection.get_Item()
    GridDataCellElement.UpdateInfoCore()
    GridCellElement.UpdateInfo()
    GridTableElement.UpdateCellContentByColumn()
    GridTableElement.UpdateViewCore()
    GridTableElement.UpdateView()
    GridTableElement.ProcessTemplateEvent()
    GridTableElement.Telerik.WinControls.UI.IGridViewEventListener.ProcessEvent()
    GridViewEventProcessEntity.ProcessCollection()
    GridViewEventProcessEntity.ProcessEvent()
    GridViewSynchronizationService.NotifyListeners()
    GridViewSynchronizationService.FlushEvents()
    GridViewSynchronizationService.DispatchEvent()
    GridViewSynchronizationService.DispatchEvent()
    GridViewSelfReferenceDataProvider.DispatchDataViewChangedEvent()
    GridViewSelfReferenceDataProvider.Refresh()
    GridViewTemplate.Telerik.WinControls.Data.IDataItemSource.Initialize()
    RadListSource`1.Initialize()
    RadListSource`1.Bind()
    RadListSource`1.set_DataSource()
    GridViewTemplate.set_DataSource()
    RadGridView.set_DataSource()
    ProjectsListUserControl.AddProjects()
    ProjectsListUserControl.RefreshProjectList()

    Does anyone have any ideas on how to troubleshoot this?

    Thanks!
    Ed

  2. Grzegorz
    Grzegorz avatar
    5 posts
    Member since:
    Feb 2013

    Posted 12 Feb 2013 Link to this post

    Hi.

    I had this issue also and I found that it is necessary to remove relations before changing datasource. Please find example code below.
    var backup = grid.Relations.ToList();
    grid.Relations.Clear();
    grid.DataSource = newSource;
    grid.Relations.AddRange(backup);

    Regards
    Grzegorz
  3. Ed
    Ed avatar
    8 posts
    Member since:
    Apr 2010

    Posted 12 Feb 2013 Link to this post

    Greg,

    Thanks for the advice.  Unfortunately, I'm already doing that as well as calling grid.ClearSelection();
    This is what my routine looks like:

    if(null != projects)
    {
        m_grid.ClearSelection();
        m_grid.Relations.Clear();
                     
        //
        //  If the grid doesn't have a filter applied, I need to ensure that the self referencing hierarchy is
        //  properly applied.
        //
        if(0 == m_grid.FilterDescriptors.Count)
        {
            if(!m_grid.Columns.Contains("ParentId"))
            {
                GridViewDataColumn col = new GridViewTextBoxColumn("ParentId", "ParentId");
                col.VisibleInColumnChooser = true;
                col.IsVisible = false;
     
                m_grid.Columns.Add(col);
            }
     
            m_grid.Relations.AddSelfReference(m_grid.MasterTemplate, "Id", "ParentId");
        }
        else
        {
            //
            //  Remove the hierarchy so that the filter works properly.  To do this, remove the relations, and the column
            //  that the relation is built on!  Cannot find a better way to do this.
            //  Telerik forums are not helpful, there are suggestions, but none work correctly.
            //
            m_grid.Relations.Clear();
            m_grid.Columns.Remove("ParentId");
        }
     
        m_grid.DataSource = null;
        m_grid.DataSource = projects;
     
        if(null != iSelectedProjectId)
        {
            FindRow(iSelectedProjectId.Value);
        }
     
        ResetContextMenu();
    }

    Thanks,
    Ed
  4. Answer
    Grzegorz
    Grzegorz avatar
    5 posts
    Member since:
    Feb 2013

    Posted 12 Feb 2013 Link to this post

    You are still adding relations before setting data source .

    m_grid.Relations.AddSelfReference(m_grid.MasterTemplate, "Id", "ParentId");

    Set data source just after cleaning relations and only then add selfrefence column.
  5. Ed
    Ed avatar
    8 posts
    Member since:
    Apr 2010

    Posted 12 Feb 2013 Link to this post

    Greg,
    You are right - once I moved the code setting the datasource property above the code that adds the self reference, it worked!

    Crazy note, this code had been working for over a year, but only recently broke when we upgraded to the latest RadControls.

    Thanks again!
    Ed
  6. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 13 Feb 2013 Link to this post

    Hello Ed,

    This a known issue for RadGridView self-reference hierarchy mode and will be fixed in one of the next releases after the upcoming Q1 2013. Please follow this link to add your vote and also subscribe to its status updates. 

    As workaround, please follow Gres's suggestionsto reset the RadGridView self-reference mode.

    Do not hesitate to contact us if you have further questions or issues. 

    Kind regards,
    Julian Benkov
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
Back to Top