DataTypeConverter on a GridViewImageColumn

3 posts, 1 answers
  1. Philippe
    Philippe avatar
    31 posts
    Member since:
    Sep 2009

    Posted 04 Jan 2012 Link to this post

    Hello,
    I seem to have a problem on my GridView : I add a column and specify its datatypeconverter this way :
    Dim col As New GridViewTextBoxColumn("Code", "Code")
    col.DataTypeConverter = New CodePluginConverter()
    gvHistorique.Columns.Insert(0, col)
    It works fine, the CanConvert and Convert methods are called as expected

    However, what I need is an image column. If I change the previous code to this :
    Dim col As New GridViewImageColumn("Code", "Code")
    col.DataTypeConverter = New CodePluginConverter()
    gvHistorique.Columns.Insert(0, col)
    All my column's cells remain empty, and I never step in any of the TypeConverter's methods.

    Is there anything obvious I don't see ? (I'm using the Q3 2011 version of the controls)

    Thanks in advance !
  2. Answer
    Svett
    Admin
    Svett avatar
    728 posts

    Posted 09 Jan 2012 Link to this post

    Hello Philippe,

    Presently, the GridViewImageColumn does not support a custom type converter. I added this request to our public issue tracking system. It will be addressed in one of the next releases. In the meantime, you can create a custom image cell where you can place your conversion logic:

    public class CustomGridImageCellElement : GridImageCellElement
    {
        public CustomGridImageCellElement(GridViewColumn col, GridRowElement row)
            : base(col, row)
        {
     
        }
     
        protected override Type ThemeEffectiveType
        {
            get
            {
                return typeof(GridImageCellElement);
            }
        }
     
        protected override void SetContentCore(object value)
        {
            Image image = null;
            // You should place your conversion logic here based on the value
            this.Image = image;
        }
    }

    You should replace the default cell instances in the CreateCell event:
    void radGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e)
    {
        if (e.CellType == typeof(GridImageCellElement))
        {
            e.CellType = typeof(CustomGridImageCellElement);
        }
    }

    I updated your Telerik points.

    Kind regards,
    Svett
    the Telerik team

    SP1
    of Q3’11 of RadControls for WinForms is available for download (see what's new).
  3. Philippe
    Philippe avatar
    31 posts
    Member since:
    Sep 2009

    Posted 09 Jan 2012 Link to this post

    OK thanks for the answer :)
Back to Top