Adding Image to ImageColumn

4 posts, 0 answers
  1. piratenwichtl
    piratenwichtl avatar
    18 posts
    Member since:
    Aug 2007

    Posted 11 Jun 2008 Link to this post

    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


  2. Nikolay
    Nikolay avatar
    1805 posts

    Posted 13 Jun 2008 Link to this post

    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,
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Marco
    Marco avatar
    4 posts
    Member since:
    Nov 2011

    Posted 21 May 2014 in reply to Nikolay Link to this post

    hello, I have the same problem. what it means "setting the image content before binding the grid"? can you post an example?

    thanks, Marco
  4. Dimitar
    Dimitar avatar
    1932 posts

    Posted 23 May 2014 Link to this post

    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.

    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.
Back to Top