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 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
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.
Mark,
I'm not really sure there's a good way of doing this. The grid doesn't really keep an internal cache of what rows have been initialized through the IntializeRow method, since there are a variety of triggers for this event to keep firing (i.e. changing the value of a cell). The grid will fire the first InitializeRow event when the UltraGridRow object needs to be created, so the closest to the concept of this cache is the array of rows that the grid holds onto. The only real way to clear this cache would be to re-bind the grid, I believe, since this will then mimic the original behavior that you're experiencing; the grid should be reusing UIElements as possible, so you are not losing everything, but this obviously is not an ideal situation.
-Matt
Hi Vince, Thank you for the reply. Unfortunately, re-initting a single row doen't work for our scenario - as re-initting all rows (11,000) is undesired. It would be better if we would re-init only the rows that have been initted - or optimally, just reset the internal "initted" cache state in the ultragrid so that it will re-init the ones it needs to as needed, just as it does immediately after binding. Is this possible?
Thank you,
The UltraGridRow object also has a Refresh() method. Calling Refresh(RefreshRow.FireInitializeRow) on an individual row should cause only that row to be re-initialized, in the same way that calling Rows.Refresh(RefreshRow.FireInitializeRow) on the grid does the same to all rows in the grid.