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

Adding Image to ImageColumn

3 Answers 421 Views
GridView
This is a migrated thread and some comments may be shown as answers.
piratenwichtl
Top achievements
Rank 1
piratenwichtl asked on 11 Jun 2008, 02:13 PM
Hi Telerik,

i got a GridView with a ImageColumn

within the cellFormatting event I do the following:

            if (e.CellElement.ColumnInfo is GridViewImageColumn)
            {
                if (e.CellElement.Image == null)
                {
                    if (((GridViewImageColumn)e.CellElement.ColumnInfo).FieldName == "PicturePath")
                    {
                        string strPath = ((GridImageCellElement)e.CellElement).Value.ToString();
                        if (strPath != string.Empty)
                        {
                            e.CellElement.Image = new Bitmap(strPath);
                            e.CellElement.ImageLayout = ImageLayout.Stretch;
                        }
                    }


this works fine basically, but when I get to a certain number of records it gets considerably slow when scrolling (because it has to repaint the grid again....)

I also noticed, when scrolling forward and backwards it randomly places displayed images within the column (even to record who actually dont have an image yet)


Any idea how to improve the performance and how to get around the scrolling issue?

thank you

cheers

Christian

3 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 13 Jun 2008, 03:55 PM
Hi Christian Menhofer,

The CellFormatting event is fired whenever a cell changes its visible state. Therefore, when scrolling your grid, this event is fired many times for each cell that becomes visible even for a moment. This may lead to slower performance.

Instead, I would suggest traversing RadGridView's Rows and Cells collections where you can implement your logic. Alternatively, I would suggest setting the image content before binding the grid, instead of making changes at runtime.

If you have additional questions, feel free to contact me.

Best wishes,
Nikolay
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Marco
Top achievements
Rank 1
answered on 21 May 2014, 02:44 PM
hello, I have the same problem. what it means "setting the image content before binding the grid"? can you post an example?

thanks, Marco
0
Dimitar
Telerik team
answered on 23 May 2014, 12:58 PM
Hi Marco,

My colleague Nikolay wants to say that the CellFormatting event is not an appropriate place to set the images for a image column. In this case you can set the images once when the grid is initialized and then you can change them if particular a value is changed. I have prepared a small sample to show you how such functionality can be achieved. Could you please check it and let me know how it fits in your case?

I hope this helps.

Regards,
Dimitar
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
piratenwichtl
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Marco
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or