Completed
Last Updated: 20 Sep 2016 06:48 by ADMIN
ADMIN
Dess | Tech Support Engineer, Sr.
Created on: 12 Sep 2016 05:56
Category: VirtualGrid
Type: Bug Report
1
FIX. RadVirtualGrid - columns disappear after resizing
To reproduce:

public Form1()
{
    InitializeComponent();

    this.radVirtualGrid1.ColumnCount = 5;
    this.radVirtualGrid1.RowCount = 20;
    this.radVirtualGrid1.CellValueNeeded += radVirtualGrid1_CellValueNeeded;
}

private void radVirtualGrid1_CellValueNeeded(object sender, Telerik.WinControls.UI.VirtualGridCellValueNeededEventArgs e)
{
    e.Value = "Data" + e.RowIndex + "." + e.ColumnIndex;
}

Workaround: use a custom ScrollableVirtualCellsContainer:

public Form1()
{
    InitializeComponent();
    this.radVirtualGrid1.CreateRowElement += radVirtualGrid1_CreateRowElement;
    this.radVirtualGrid1.ColumnCount = 5;
    this.radVirtualGrid1.RowCount = 20;
    this.radVirtualGrid1.CellValueNeeded += radVirtualGrid1_CellValueNeeded;
}

private void radVirtualGrid1_CreateRowElement(object sender, VirtualGridCreateRowEventArgs e)
{
    e.RowElement = new CustomVirtualGridRowElement();
}

private void radVirtualGrid1_CellValueNeeded(object sender, Telerik.WinControls.UI.VirtualGridCellValueNeededEventArgs e)
{
    e.Value = "Data" + e.RowIndex + "." + e.ColumnIndex;
}

public class CustomVirtualGridRowElement : VirtualGridRowElement
{
    public CustomVirtualGridRowElement()
        : base()
    {
        FieldInfo fi = typeof(VirtualGridRowElement).GetField("scrollableColumns", BindingFlags.NonPublic | BindingFlags.Instance);
        ScrollableVirtualCellsContainer scrollableColumns = fi.GetValue(this) as ScrollableVirtualCellsContainer;
        CustomScrollableVirtualCellsContainer newScrollableColumns = new CustomScrollableVirtualCellsContainer();
        FieldInfo fi2 = typeof(ScrollableVirtualCellsContainer).GetField("rowElement", BindingFlags.NonPublic | BindingFlags.Instance);
        fi2.SetValue(newScrollableColumns, this);
        this.Children.Remove(scrollableColumns);
        this.Children.Insert(1, newScrollableColumns);
    }
}

public class CustomScrollableVirtualCellsContainer : ScrollableVirtualCellsContainer
{
    protected override SizeF MeasureElementCore(RadElement element, SizeF availableSize)
    {
        int scrollOffset = 0;

        if (this.RowElement.TableElement.ColumnScroller.ScrollMode == ItemScrollerScrollModes.Discrete)
        {
            for (int i = 0; i < this.RowElement.TableElement.ColumnScroller.Scrollbar.Value; i++)
            {
                scrollOffset += this.RowElement.TableElement.ColumnScroller.GetScrollHeight(
                    this.RowElement.TableElement.ViewInfo.ColumnsViewState.GetItemSize(i));
            }
        }
        else
        {
            scrollOffset = this.RowElement.TableElement.HScrollBar.Value;
        }

        VirtualGridCellElement cellElement = element as VirtualGridCellElement;

        int itemOffset = this.RowElement.ViewInfo.ColumnsViewState.GetItemOffset(cellElement.Data);
        int itemWidth = this.RowElement.ViewInfo.ColumnsViewState.GetItemSize(cellElement.Data);

        element.Measure(availableSize);

        if (itemOffset + itemWidth > scrollOffset && itemOffset < scrollOffset)
        {
            return new SizeF((itemOffset + itemWidth) - scrollOffset, element.DesiredSize.Height);
        }

        return element.DesiredSize;
    }
}
Attached Files:
(Total attached files size should be smaller than 20mb. Allowed extensions: .zip, .rar, .jpg, .png, .gif)
0 comments