This is a migrated thread and some comments may be shown as answers.

DataTypeConverter on a GridViewImageColumn

2 Answers 139 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Philippe
Top achievements
Rank 1
Philippe asked on 04 Jan 2012, 03:39 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Svett
Telerik team
answered on 09 Jan 2012, 10:13 AM
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).
0
Philippe
Top achievements
Rank 1
answered on 09 Jan 2012, 10:26 AM
OK thanks for the answer :)
Tags
GridView
Asked by
Philippe
Top achievements
Rank 1
Answers by
Svett
Telerik team
Philippe
Top achievements
Rank 1
Share this question
or