Skip to main content

Use Custom Icons for Field List Items

  • 2 minutes to read

View Example: Reporting for WinForms - Custom Icons for Field List Items in the End-User Designer

The following code snippet implements and registers a DevExpress.Data.Browsing.Design.ColumnImageProvider descendant that returns a custom SVG image to be displayed as an icon for the CategoryName field in the Field List:

using System;
using System.Windows.Forms;
using DevExpress.XtraReports.UI;
// ...

namespace FieldListCustomIcons {
    public partial class Form1 : Form {

        public Form1() {
            InitializeComponent();
            DevExpress.Data.Browsing.Design.ColumnImageProvider.Instance = new CustomColumnImageProvider();
        }

        private void button1_Click(object sender, EventArgs e) {
            XtraReport1 report = new XtraReport1();
            ReportDesignTool designTool = new ReportDesignTool(report);
            designTool.ShowDesignerDialog();
        }
    }
}
using System.ComponentModel;
using DevExpress.Utils;
using DevExpress.Utils.Svg;

namespace FieldListCustomIcons {

    class CustomColumnImageProvider : DevExpress.Data.Browsing.Design.ColumnImageProvider {
        int categoryNameIndex;

        public override int GetColumnImageIndex(PropertyDescriptor property, 
            DevExpress.Data.Browsing.Design.TypeSpecifics specifics) {
            if (property.Name.Equals("CategoryName"))
                return categoryNameIndex;
            return base.GetColumnImageIndex(property, specifics);
        }
        public override SvgImageCollection CreateSvgImageCollection() {
            SvgImageCollection result = base.CreateSvgImageCollection();
            SvgImage image = new SvgImage(typeof(CustomColumnImageProvider), "FieldListCustomIcons.StarIcon.svg");

            result.Add(image);
            categoryNameIndex = result.Count - 1;

            return result;
        }

    }
}

The result is shown in the following image:

field-list-custom-icons

See Also