I have a performance problem looping through Selected.cells and setting the Value property for thousands of checkboxes in UltraGrid. I would like to do this at once in constant time. and update the datasource when the user clicks save.
I have tried different things and I am not able to implement InitializeRow to effect this as suggested in some of the forum post.
kindly advise
Hello Abayomi,
I have been investigating into this behavior you are referring to in this case, and it sounds like this performance issue you are seeing is likely coming from a large amount of property change notifications - possibly tied to an implementation of the INotifyPropertyChanged interface on your underlying property to the checkbox column. I cannot be sure of this though, as I do not know exactly what structure your data item is set up in. I can still make a recommendation in this case, though.
The best recommendation I can make without knowing more about your scenario is to try the Begin/End Update() methods along with the Suspend/Resume RowSynchronization() updates in this case. The code for this could look like the following, although if your call here is happening synchronously, this may not work:
grid.BeginUpdate(); grid.SuspendRowSynchronizion(); try { // set checkbox values here } finally { grid.ResumeRowSynchronizion(); grid.EndUpdate(); }
If this doesn't work for you, then would it be possible for you to please provide an isolated sample project that demonstrates this performance issue that you are seeing? I also find it rather strange that you had mentioned that you are looping through the Selected.Cells collection, but are updating thousands of records in this case. Perhaps a select-all operation happened on your users side? Can you please elaborate a bit further on this?
Please let me know if you have any other questions or concerns on this matter.
Yes a select-all happens on the user side. The user can Shift+Click a collection of rows at once and then hit the Space-key to check all boxes. So when the user makes the selection, ,y logic is to add all the selection to the collection "Selected" and then try to update the Cell.Value since I can not set Cell.Text {which i presume might be faster}
Thank you for clarifying exactly what is happening in your application. I am curious, did you get a chance to implement the suggestions made above that use the Being/EndUpdate() and Suspend/ResumeRowSynchronization() methods? Did this help?
The methods did not help solve the issue. I'm trying to see how to create a sample of the issue or are there any other suggestions to the code below?? because I can't seems to identify how the property change notifications affects the performance but I see that the code { c.Value = CheckState.Checked} takes longer time to set the Value property {up to some secs per cell Value change) and browsing through the forum, I t was suggested to try to use InitializeRow() to change the values. I don't know how to do that.
Thanks
BeginUpdate(); SuspendRowSynchronization(); try { foreach (UltraGridCell c in Selected.Cells) // Selection were made with individual cell select { c.Value = CheckState.Checked; } } finally { ResumeRowSynchronization(); EndUpdate(); }
InitializeRow won't do you any good here. That's for initializing the values of an unbound column or performing some action on the row based on some value in a cell. It doesn't apply here.
Changing thousands of cell values at once it probably going to take some time and there may not be any way around that. But it might be that your application is doing something that is slowing it down, or operating upon the cells in a way that is not optimal. So if you could provide a small sample project demonstrating the problem you are seeing, we could take a look and see if there is some way to speed it up.
The code you have here seems okay. The only thing puzzling here is that you are using "CheckState.Checked" instead of "true". Is your column's DataType really CheckState? Why are you using that instead of Boolean? Is this column supporting the Indeterminate state for some reason?
One other thing you could try, as a test, would be to set the Visual Studio IDE to break on all run-time exceptions. Exceptions that are getting caught and handled will cause a significant performance hit. So maybe you are getting exceptions you are not aware of and that's what is slowing it down.
Thanks for your response. I realized that in my application, I have lot of events being triggered whenever each checkbox value is changed and the implementation of the event handlers need to be refactored for performance gain. this was helpful to resolve it.