To reproduce:
Create a self reference RadGridView and add enough columns so that a horizontal scrollbar appears. Scroll the horizontal scrollbar to the right and close the form. You will see an exception.
Workaround:
Create a custom row element in the CreateRow event:
void radGridView1_CreateRow(object sender, Telerik.WinControls.UI.GridViewCreateRowEventArgs e)
{
if (e.RowInfo is GridViewHierarchyRowInfo || e.RowInfo is GridViewDataRowInfo)
{
e.RowElement = new MyDataRowElement();
}
}
public class MyLayout : SelfReferenceCellLayout
{
public MyLayout(GridRowElement rowElement) : base(rowElement) { }
public override void DetachCellElements()
{
if (this.StackLayoutElement != null)
{
base.DetachCellElements();
}
}
}
public class MyDataRowElement : GridDataRowElement
{
private MyLayout cellReferenceLayout;
public override void Detach()
{
base.Detach();
if (this.cellReferenceLayout != null)
{
this.cellReferenceLayout.DetachCellElements();
}
}
protected override void DisposeManagedResources()
{
if (this.cellReferenceLayout != null)
{
this.cellReferenceLayout.Dispose();
}
base.DisposeManagedResources();
}
public override SelfReferenceCellLayout SelfReferenceLayout
{
get
{
if (this.RowInfo is GridViewHierarchyRowInfo)
{
if (this.ViewTemplate != null &&
this.ViewTemplate.IsSelfReference &&
this.cellReferenceLayout == null)
{
this.cellReferenceLayout = new MyLayout(this);
}
return this.cellReferenceLayout;
}
return null;
}
}
protected override Type ThemeEffectiveType
{
get
{
return typeof(GridDataRowElement);
}
}
}