Completed
Last Updated: 02 Jun 2014 12:02 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 28 Apr 2014 10:39
Category:
Type: Bug Report
0
FIX. RadListView - ListView item's text is cut off
When using vertical IconView with AllowArbitraryItemHeight = true or horizontal IconVIew with AllowArbitraryItemWidth = true in some cases the last items are cut.

To reproduce:
1. Add a RadListView and use the following code snipept:

public Form1()
{
    InitializeComponent();

    string[] lines = Properties.Resources.Folders.Split(Environment.NewLine.ToArray(),
        StringSplitOptions.RemoveEmptyEntries);
    BindingList<string> items = new BindingList<string>();
    this.radListView1.BeginUpdate();
    foreach (string line in lines)
    {
        this.radListView1.Items.Add(line);
    }
    this.radListView1.EndUpdate();
    
    this.radListView1.ViewType = Telerik.WinControls.UI.ListViewType.IconsView;
    radListView1.ListViewElement.ViewElement.Orientation = Orientation.Horizontal;
    radListView1.AllowArbitraryItemWidth = true;
    radListView1.AllowArbitraryItemHeight = false;
}

Workaround:
public class CustomListView : RadListView
{
    public override string ThemeClassName
    {
        get
        {
            return typeof(RadListView).FullName;
        }
        set
        {
            base.ThemeClassName = value;
        }
    }

    protected override RadListViewElement CreateListViewElement()
    {
        return new CustomListViewElement();
    }
}

public class CustomListViewElement : RadListViewElement
{
    protected override BaseListViewElement CreateViewElement()
    {
        if (this.ViewType == ListViewType.IconsView)
        {
            return new CustomIconViewElement(this);
        }
        return base.CreateViewElement();
    }

    protected override Type ThemeEffectiveType
    {
        get
        {
            return typeof(RadListViewElement);
        }
    }
}

public class CustomIconViewElement : IconListViewElement
{
    public CustomIconViewElement(RadListViewElement owner)
        : base(owner)
    {

    }

    protected override VirtualizedStackContainer<ListViewDataItem> CreateViewElement()
    {
        return new CustomIconViewContainer(this);
    }

    protected override Type ThemeEffectiveType
    {
        get
        {
            return typeof(IconListViewElement);
        }
    }
}

public class CustomIconViewContainer : IconListViewContainer
{
    public CustomIconViewContainer(IconListViewElement owner)
        : base(owner)
    {

    }

    private bool Grouped
    {
        get
        {
            return this.owner.Owner.ShowGroups && (this.owner.Owner.EnableCustomGrouping || this.owner.Owner.EnableGrouping);
        }
    }

    RectangleF clientRect;

    protected override bool BeginMeasure(SizeF availableSize)
    {
        this.clientRect = new RectangleF(Padding.Left, Padding.Top,
                                         availableSize.Width - Padding.Horizontal, availableSize.Height - Padding.Vertical);
        return base.BeginMeasure(availableSize);
    }

    protected override SizeF ArrangeVertical(SizeF finalSize)
    {
        float x = clientRect.X, y = clientRect.Y + this.ScrollOffset.Height;

        float maxHeight = 0;
        float maxWidth = 0;

        foreach (RadElement element in this.Children)
        {
            BaseListViewVisualItem visualItem = element as BaseListViewVisualItem;
            if (visualItem == null || visualItem.Data == null)
                continue;

            Size elementSize = this.ElementProvider.GetElementSize(visualItem.Data).ToSize();

            if (element is BaseListViewGroupVisualItem)
            {
                if (x != clientRect.X)
                {
                    x = clientRect.X;
                    y += maxHeight;
                    maxHeight = elementSize.Height;
                }

                maxHeight = Math.Max(maxHeight, elementSize.Height);
                maxWidth = Math.Max(maxWidth, elementSize.Width);

                RectangleF arrangeRect = new RectangleF(new PointF(x, y), elementSize);
                
                element.Arrange(arrangeRect);

                x = clientRect.X;
                y += elementSize.Height + this.ItemSpacing;
            }
            else
            {
                if (x + elementSize.Width > clientRect.Right && x != clientRect.X)
                {
                    x = clientRect.X;
                    y += maxHeight + this.ItemSpacing;
                    maxHeight = elementSize.Height;
                }

                maxHeight = Math.Max(maxHeight, elementSize.Height);
                maxWidth = Math.Max(maxWidth, elementSize.Width);

                if (x == clientRect.X &&
                    this.Grouped &&
                    (this.owner.Owner.Groups.Count > 0) &&
                    !this.owner.Owner.FullRowSelect)
                {
                    x += this.owner.Owner.GroupIndent;
                }

                RectangleF arrangeRect = new RectangleF(new PointF(x, y), elementSize);
                if (this.RightToLeft)
                {
                    arrangeRect = LayoutUtils.RTLTranslateNonRelative(arrangeRect, clientRect);
                }

                element.Arrange(arrangeRect);
                x += elementSize.Width + this.ItemSpacing;
            }
        }

        return finalSize;
    }

    protected override System.Drawing.SizeF ArrangeUngroupedHorizontal(System.Drawing.SizeF finalSize)
    {
        float x = clientRect.X + this.ScrollOffset.Width, y = clientRect.Y;

        float maxHeight = 0;
        float maxWidth = 0;

        foreach (RadElement element in this.Children)
        {
            BaseListViewVisualItem visualItem = element as BaseListViewVisualItem;
            if (visualItem == null || visualItem.Data == null)
                continue;

            Size elementSize = this.ElementProvider.GetElementSize(visualItem.Data).ToSize();

            if (y + elementSize.Height > clientRect.Bottom && y != clientRect.Y)
            {
                y = clientRect.Y;
                x += maxWidth + this.ItemSpacing;
                maxWidth = elementSize.Width;
            }

            maxHeight = Math.Max(maxHeight, elementSize.Height);
            maxWidth = Math.Max(maxWidth, elementSize.Width);

            RectangleF arrangeRect = new RectangleF(new PointF(x, y), elementSize);
            if (this.RightToLeft)
            {
                arrangeRect = LayoutUtils.RTLTranslateNonRelative(arrangeRect, clientRect);
            }

            element.Arrange(arrangeRect);
            y += elementSize.Height + this.ItemSpacing;
        }

        return finalSize;
    }

    protected override Type ThemeEffectiveType
    {
        get
        {
            return typeof(IconListViewContainer);
        }
    }
}
Attached Files:
0 comments