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

Change Row Back colour In for Loop

2 Answers 183 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Manikandan
Top achievements
Rank 1
Manikandan asked on 31 Oct 2009, 02:30 AM
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 Answers, 1 is accepted

Sort by
0
Anand T
Top achievements
Rank 1
answered on 20 Nov 2009, 02:27 PM

0
Robert
Top achievements
Rank 1
answered on 23 Nov 2009, 10:37 PM
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




Tags
GridView
Asked by
Manikandan
Top achievements
Rank 1
Answers by
Anand T
Top achievements
Rank 1
Robert
Top achievements
Rank 1
Share this question
or