Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
267
Force InitializeRow again for visible rows?
posted

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?

 

I've got some custom appearance code in my InitalizeRow handler for a grid with thousands of rows. The UltraGrid is doing a great job of only raising the event for the rows that are currently visible and it must keep track of which rows have been visible as the event is not re-raised when a row that was visible is scrolled out of view and then back into view. This is good. 

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.

 Refresh() and Update() don't seem right. Calling DataBind() seems heavy-handed. I appreciate any suggestions.Best,Mark

 

Parents
  • 469350
    Offline posted

    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.

Reply Children
No Data