Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1960
Sort indicator image - Can it be changed?
posted

Hello, 

Is there a way to chage the sort indicator images? I mean the up and down arrows displayed on the header when sorting is ascending or descendig

  • 69832
    Verified Answer
    Offline posted

    Yes; the following code sample demonstrates how using the IUIElementCreationFilter interface:

    this.ultraListView1.CreationFilter = new SortIndicatorCreationFilter( ascendingImage, descendingImage );

    public class SortIndicatorCreationFilter : IUIElementCreationFilter
    {
        private Image imageAsc = null;
        private Image imageDesc = null;

        public SortIndicatorCreationFilter( Image imageAsc, Image imageDesc )
        {
            this.imageAsc = imageAsc;
            this.imageDesc= imageDesc;
        }

        void IUIElementCreationFilter.AfterCreateChildElements(UIElement parent)
        {
            UltraListViewColumnHeaderUIElement headerElement = parent as UltraListViewColumnHeaderUIElement;
            if ( headerElement != null )
            {
                UltraListViewSortIndicatorUIElement sortIndicator =
                    headerElement.GetDescendant( typeof(UltraListViewSortIndicatorUIElement) ) as
                    UltraListViewSortIndicatorUIElement;

                if ( sortIndicator != null )
                {
                    UltraListViewColumnBase column = headerElement.Column;
                    Sorting sorting = column.Sorting;
                    Image image = sorting == Sorting.Ascending ? this.imageAsc : this.imageDesc;
                    Rectangle rect = sortIndicator.Rect;
                    headerElement.ChildElements.Remove( sortIndicator );
                    ImageUIElement imageElement = new ImageUIElement( headerElement, image );
                    imageElement.Rect = rect;
                    headerElement.ChildElements.Add( imageElement );
                }
            }
        }

        bool IUIElementCreationFilter.BeforeCreateChildElements(UIElement parent)
        {
            return false;
        }
    }