Change Row Back colour In for Loop

3 posts, 0 answers
  1. Manikandan
    Manikandan avatar
    13 posts
    Member since:
    Apr 2009

    Posted 30 Oct 2009 Link to this post

    How to change the row back color of the rows in for loop after binding the data source.Without using the Radgridview Events how to change the row back color in for loop / For each loop of the radgridview rows?
  2. Anand T
    Anand T avatar
    4 posts
    Member since:
    Jul 2009

    Posted 20 Nov 2009 Link to this post

  3. Robert
    Robert avatar
    82 posts
    Member since:
    Jun 2009

    Posted 23 Nov 2009 Link to this post

    Hello Manikandan,

    Changing the background color of rows in the RadGridView this way can be problematic as the visual element for specific rows is not guaranteed to be available unless you access it through the formatting event. Also, in experimenting with the RadGridView, I've noticed that it seems to be reusing the same few visual elements in an effort to increase performance and decrease memory usage. This means that if you set the BackColor up front, it will be permanently set based on the initial set of visible rows. You won't be able to format the rows based on their values.

    i.e. If I have a RadGridView with 20 rows and only 10 rows are visible up front, I will have access to set 10 visual elements. The visual elements for the rest of the rows will be null. When I use the scroll bar to scroll through the records, the initial 10 visual elements will be re-used for all records I scroll through. Therefor, if I don't set them again, they will remain their initial color.

    Also, there is the case where if your application is resizable, the RadGridView will need to create new visual elements if its size increases. These elements will not have been set in your initial foreach loop.

    I think the best/safest route for you to take is using the RowFormatting event as described here:

    I hope this information helps.

    - Robert

Back to Top