Completed
Last Updated: 10 Mar 2015 10:57 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 18 Feb 2015 11:57
Category: PropertyGrid
Type: Bug Report
0
FIX. RadPropertyGrid - Incorrect scroll-bar range when scrolling up and down
To reproduce: 

1. Add a RadPropertyGrid and populate it with all of of  items by using the following code:
                      this.radPropertyGrid1.SelectedObject = this;
2. Expand two items.
3. Scroll to the bottom.
4. Scroll to the top.
5. If you scroll to the bottom again, you will see a lot of empty space. The attached gif file illustrates better the problem.

Workaround:
public Form1()
{
    InitializeComponent();

    this.radPropertyGrid1.SelectedObject = this;
    this.radPropertyGrid1.PropertyGridElement.PropertyTableElement.Scroller.Traverser =
        new CustomPropertyGridTraverser(this.radPropertyGrid1.PropertyGridElement.PropertyTableElement);
}

public class CustomPropertyGridTraverser : PropertyGridTraverser
{
    public CustomPropertyGridTraverser(PropertyGridTableElement propertyGridElement) : base(propertyGridElement)
    {
    }

    public int Index
    {
        get
        {
            FieldInfo fi = typeof(PropertyGridTraverser).GetField("index", BindingFlags.NonPublic | BindingFlags.Instance);
            return int.Parse(fi.GetValue(this).ToString());
        }
        set 
        {
            FieldInfo fi = typeof(PropertyGridTraverser).GetField("index", BindingFlags.NonPublic | BindingFlags.Instance);
            fi.SetValue(this, value);
        }
    }

    public int GroupIndex
    {
        get
        {
            FieldInfo fi = typeof(PropertyGridTraverser).GetField("groupIndex", BindingFlags.NonPublic | BindingFlags.Instance);
            return int.Parse(fi.GetValue(this).ToString());
        }
    }

    public PropertyGridTableElement Element
    {
        get
        {
            FieldInfo fi = typeof(PropertyGridTraverser).GetField("propertyGridElement", BindingFlags.NonPublic | BindingFlags.Instance);
            return fi.GetValue(this) as PropertyGridTableElement ;
        }
    }

    public PropertyGridItemBase Item
    {
        get
        {
            FieldInfo fi = typeof(PropertyGridTraverser).GetField("item", BindingFlags.NonPublic | BindingFlags.Instance);
            return fi.GetValue(this) as PropertyGridItemBase ;
        }
        set 
        {
            FieldInfo fi = typeof(PropertyGridTraverser).GetField("item", BindingFlags.NonPublic | BindingFlags.Instance);
            fi.SetValue(this, value);
        }
    }

    protected override bool MovePreviousFromDataItem(PropertyGridItemBase currentItem)
    {
        if (currentItem.Parent != null && currentItem.Parent.GridItems.Count > 0)
        {
            if (this.Index > 0)
            {
                PropertyGridItemBase prevItem = currentItem.Parent.GridItems[--this.Index];
                if (prevItem.Expandable && (prevItem.Expanded || this.TraverseHirarchy))
                {
                    prevItem = this.GetLastChild(prevItem);
                }

                this.Item = prevItem;
                return true;
            }

            this.Item = currentItem.Parent;
            this.Index = -1;
            if (currentItem.Parent.Parent != null)
            {
                this.Index = currentItem.Parent.Parent.GridItems.IndexOf(currentItem.Parent as PropertyGridItem);
            }
            else
            {
                if (this.Element.CollectionView.Groups.Count == 0)
                {
                    this.Index = this.Element.CollectionView.IndexOf(currentItem.Parent as PropertyGridItem);
                }
                else
                {
                    this.Index = this.Element.CollectionView.Groups[this.GroupIndex].IndexOf(currentItem.Parent as PropertyGridItem);
                }
            }
            return true;
        }
        return base.MovePreviousFromDataItem(currentItem);
    }
}
0 comments