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

How to bind a picture to a column?

1 Answer 193 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dan Harvey
Top achievements
Rank 2
Dan Harvey asked on 14 Oct 2009, 08:31 PM
Hello,

I was trying to use the radgrid and I have 2 columns.  One column has the names of files (example, test.docx, Instructions.pdf)  and the other column I want to use to display the icons for these different extensions (example, display a word icon for word documents and so on).  I am currently using a binding source to bring back the filenames for the first column and the second column is blank. 

How do I set the picture in that column through code?  I do not need the logic to display the correct icon, I just can't figure out how to populate the column with my own information.

Thanks,

1 Answer, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 15 Oct 2009, 08:59 AM
Hello dan,

You can do this when handling CellFormatting event. You should set the Image property for the column. Because CellFormatting fires frequently I suggest that you hold your images in a image list. Here is a sample:

this.radGridView1.CellFormatting += new CellFormattingEventHandler(radGridView1_CellFormatting);
this.radGridView1.Columns.Add(new GridViewImageColumn("images", ""));
 
void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.CellElement is GridImageCellElement)
    {
        e.CellElement.ImageLayout = ImageLayout.Zoom;
        e.CellElement.Image = Resources.blue;
    }
}

I hope this helps.

All the best,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Dan Harvey
Top achievements
Rank 2
Answers by
Jack
Telerik team
Share this question
or