Completed
Last Updated: 15 Aug 2017 10:28 by ADMIN
ADMIN
Dimitar
Created on: 17 Mar 2017 07:31
Category: VirtualGrid
Type: Bug Report
2
FIX. RadVirtualGrid - exception when setting the current cell to null.
To reproduce:
void radButton1_Click(object sender, EventArgs e)
{
    this.radVirtualGrid1.CurrentCell = null;
}

Workaround:

class MyRadVirtualGrid : RadVirtualGrid
{
    protected override void CreateChildItems(RadElement parent)
    {
        base.CreateChildItems(parent);
        parent.Children.RemoveAt(0);
        var field = typeof(RadVirtualGrid).GetField("virtualGridElement", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
        var element = new MyVirtualGridElement();
        field.SetValue(this,element);

        
        parent.Children.Add(element);
    }
}
class MyVirtualGridElement : RadVirtualGridElement
{
    protected override Type ThemeEffectiveType
    {
        get { return typeof(RadVirtualGridElement); }
    }
    protected override bool SetCurrentCell(VirtualGridCellInfo value)
    {
        if (value == null)
        {
            if (this.IsInEditMode && !this.EndEdit())
            {
                return false;
            }

            int row = int.MinValue;
            VirtualGridViewInfo viewInfo = null;

            if (this.CurrentCell != null)
            {
                row = this.CurrentCell.RowIndex;
                viewInfo = this.CurrentCell.ViewInfo;
            }

            if (this.CurrentCell != null && (value == null || this.CurrentCell.ViewInfo != value.ViewInfo || this.CurrentCell.RowIndex != value.RowIndex))
            {
                VirtualGridRowValidatingEventArgs e = new VirtualGridRowValidatingEventArgs(row, viewInfo);
                this.OnRowValidating(e);

                if (e.Cancel)
                {
                    return false;
                }
            }
            var currentCell = typeof(RadVirtualGridElement).GetField("currentCell", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            currentCell.SetValue(this, value);

            if (this.CurrentCell != null)
            {
                this.EnsureCellVisible(this.CurrentCell.RowIndex, this.CurrentCell.ColumnIndex, this.CurrentCell.ViewInfo);
            }

            VirtualGridTableElement tableElement = null;

            if (this.CurrentCell != null)
            {
                tableElement = this.GetTableElement(this.CurrentCell.ViewInfo);
            }
            else
            {
                tableElement = this.TableElement;
            }
            

            if (tableElement != null)
            {
                VirtualGridRowElement rowElement = tableElement.ViewElement.GetRowElement(row);

                if (rowElement != null)
                {
                    rowElement.Synchronize(false);
                }
            }

            if (value != null)
            {
                tableElement = this.GetTableElement(value.ViewInfo);
                if (tableElement != null)
                {
                    VirtualGridRowElement rowElement = tableElement.ViewElement.GetRowElement(value.RowIndex);

                    if (rowElement != null)
                    {
                        rowElement.Synchronize(false);
                    }
                }
            }

            if (viewInfo != null)
            {
                VirtualGridRowEventArgs args = new VirtualGridRowEventArgs(row, viewInfo);
                this.OnRowValidated(args);
            }

            this.OnCurrentCellChanged(EventArgs.Empty);

            return true;
        }
        return base.SetCurrentCell(value);
    }
}


0 comments