Skip to content

Infragistics Community Forum / Desktop / Ultimate UI for Windows Forms / Force InitializeRow again for visible rows?

Force InitializeRow again for visible rows?

New Discussion
Mark
Mark asked on Dec 1, 2008 4:49 PM

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

 

Sign In to post a reply

Replies

  • 0
    [Infragistics] Vince McDonald
    [Infragistics] Vince McDonald answered on Nov 24, 2008 4:41 PM

    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.

    • 0
      Mark
      Mark answered on Nov 24, 2008 7:10 PM

      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,

      Mark

      • 0
        Matt Snyder
        Matt Snyder answered on Nov 24, 2008 7:43 PM

        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

  • 0
    Mike Saltzman
    Mike Saltzman answered on Dec 1, 2008 4:08 PM

    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.

    • 0
      Mark
      Mark answered on Dec 1, 2008 4:49 PM

      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

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Mark
Favorites
0
Replies
5
Created On
Dec 01, 2008
Last Post
17 years, 8 months ago

Suggested Discussions

Created by

Created on

Dec 1, 2008 4:49 PM

Last activity on

Feb 11, 2026 9:51 PM