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

Refreshing self referencing grid causes error

5 Answers 142 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ed
Top achievements
Rank 1
Ed asked on 11 Feb 2013, 10:44 PM

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

5 Answers, 1 is accepted

Sort by
0
Grzegorz
Top achievements
Rank 1
answered on 12 Feb 2013, 06:45 AM
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
0
Ed
Top achievements
Rank 1
answered on 12 Feb 2013, 01:54 PM
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
0
Accepted
Grzegorz
Top achievements
Rank 1
answered on 12 Feb 2013, 02:11 PM
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.
0
Ed
Top achievements
Rank 1
answered on 12 Feb 2013, 02:16 PM
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
0
Julian Benkov
Telerik team
answered on 13 Feb 2013, 05:43 PM
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.
Tags
GridView
Asked by
Ed
Top achievements
Rank 1
Answers by
Grzegorz
Top achievements
Rank 1
Ed
Top achievements
Rank 1
Julian Benkov
Telerik team
Share this question
or