Is there a way for force InitializeRow() to be raised again for the visible rows and clear the cached state of rows that were once in view?
Imagine I have a color picker above the grid where the user can pick a color for rows that meet certain criteria. When the user changes that color, I don't want to call Rows.Refresh(RefreshRow.FireInitializeRow) as I observed this fires the event for all rows, not just the visible ones. I thought perhaps one option would be to iterate over just the visible rows explicitly refreshing them, but this doesn't handle the case where a row was visible and now scrolled out of the visible area - the grid won't raise the event again when the row is scrolled into view.
Hi Mark,
In your example, with the color picker, what exactly do you want to happen to the grid when the user changes a color? Because it seems to me that you might be going about this in a roundabout way.
I assume you are using InitializeRow to color a row or cell based on the value of a cell in that row (or some criteria related to the row). If that's the case, then how are you doing it? There are two ways you could be doing this:
1) You set the Appearance.BackColor on the row/cell:
e.Row.Appearance.BackColor = Color.Red;
2) You set the Appearance on the row/cell:
e.Row.Appearance = grid.DisplayLayout.Appearances["MyAppearance"];
The second method is more efficient in almost every case, but in your example of the color picker, it's even more important, because it allows you to change the appearance everywhere it is used. So when the use picks a new color, all you do is:
grid.DisplayLayout.Appearance["MyAppearance"].BackColor = colorPicker.Color;
This will update every row or cell where the appearance is used without re-initializing anything that doesn't need to be.
Hi Mike, thank you for the reply. The color picker example was contrived to keep it simple. In my case, initializeRow is setting the Cell.Style, Activation and sometimes Appearance.Cursor and/or BackColor based on a number of criteria. There are some events external to the grid that will require this criteria to be re-evaluated. Currently we're just calling Rows.Refresh( FireInitializeRow) which I discovered is re-initializing every row (as documented). However, in the extreme case where my grid has 11000 rows but only 30 of them have ever been displayed to the user and thus initilized, I'd like to just re-init those 30. I can't just iterate over the currently visible rows since any row that was visible at some point (and initted) needs to be re-initted even if scrolled out of view.
After posting here, I did submit a support request on this as well (CAS-11515-AYRHPV). The skinny from Ajay was I'd have to keep track of my own list of indexes of rows that had been initialized so I can iterate myself. I had though a brute force method might be to just re-bind, but I wasn't sure how expensive that would be.
I appreciate your thoughts on this.
Note: Your tip on persisted backcolor in the grid's Appearances rather than setting once per cell was helpful.
Best,
Mark