Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

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