Hello,
Using an Ultragrid bound to a typed Binding list, if i clear the binding list then re-add items back to the binding list, including some of the original items, then i am not getting the InitializeRow event fireing for the rows that are being recycled if the grid is not visible during the refresh.
Any ideas?
Thanks
Steve
Hi Mike,
Yes, we are removing items from the list then re-adding the exact same instance, without a refresh, It sounds exactly as you describe.
As to being a bug, Its debatable. I would have expected the grid to treat it as a new row but then again our usage is not exactly ideal, it would be far better we remove just dead rows and add just new rows but we do require the grid to be empty while the data is reloaded as the data could be misleading at that point. For now however i think that the refresh option is best for our usage.
Thanks for your help
Hi Steve,
When you say "including some of the original items", are you saying that you are removing an item from the list and then adding the exact same instance of that item back into the list? If it's the same instance, than the grid is probably re-using the existing UltraGridRow object as an optimization, so it thinks that it doesn't need to re-initialize the row.
This might be a bug, but it might not. If the grid hasn't thrown away that row, then my guess is that you are clearing the BindingList and then re-adding the rows in a synchronous operation, which means as far as the grid is concerned, the row was never really removed. The grid responds to the BindingList notifications asynchronously. So if you remove a row and re-add it, the grid just marks the rows collection dirty and then updates the collection the next time the grid paints. So it's essentially one operation and since the same row with the same ListObject existed before and after the operation, it's basically treated like a no-op.
If you need to force InitializeRow to fire, then you have a couple of options. One thing you could do is force the grid to refresh after you remove all of the rows. You could do this pretty easily by calling grid.Update to force the grid to paint. This will have to effect of making the removal of the rows a synchronous operation. The grid will process the removal of the rows and then when you re-add the row(s), there should be no caching and the grid should treat every row as a new row.
Another option is to just keep doing what you are doing and then after you have added all of the rows you need, you can call grid.Rows.Refresh(FireInitializeRow) to make the grid fire the InitializeRow event for every row.