Our code calls RefreshSortPosition() from the InitializeRecord event as suggested in forum threads http://ko.infragistics.com/community/forums/p/69543/353415.aspx#353415, http://ko.infragistics.com/community/forums/p/56087/288546.aspx#288546, and http://ko.infragistics.com/community/forums/p/69543/353333.aspx#353333.
Recently, we started seeing stack overflows when the user sorts columns in the grid. This stack overflow has been traced to the RefreshSortPosition() being called from the InitializeRecord event handler. Looking at the RefreshSortPosition()’s remarks, it says:
Note: This method should not be called directly from within the Infragistics.Windows.DataPresenter.DataPresenterBase.InitializeRecordEvent. If the method needs to be called from within this event, you should do so asynchronously using Dispatcher.BeginInvoke Infragistics.Windows.DataPresenter.RecordCollectionBase.RefreshSort()
I changed our code to perform the RefreshSort(), but this slows things down tremendously. I then put the RefreshSortPosition() into a Dispatcher.BeginInvoke along with some logic to avoid it being called during a grid sort, as well as some recursion avoidance logic.
// Don't do this if we are in the middle of a sort or in
// the middle of a load
if (!this.IsSorting && this.CanClose)
{
// Avoid recursive calls
System.Diagnostics.Debug.Assert(!m_bCallingRefreshSort);
if (!m_bCallingRefreshSort)
Action action = new Action(() =>
m_bCallingRefreshSort = true;
//r.Record.ParentCollection.RefreshSort();
r.Record.RefreshSortPosition();
m_bCallingRefreshSort = false;
});
this.Dispatcher.BeginInvoke(action);
}
This seems to work.
Is this an acceptable solution, or should one never call RefreshSortPosition() from the InitializeRecordEvent?
Thanks
Dan
Hello Dan,
Thank you for your reply. I am very glad that you have managed to solve the issue that you were having. Please let me know if you need any further assistance on the matter.
Sincerely,
Krasimir
Developer Support Engineer
Infragistics
www.infragistics.com/support
Krasimir,
Thanks for your feedback. I’ll go ahead with my solution. It not only appears to have fixed my problem, but it also improved our grid load and sorting times.
I am just checking if you require any further assistance on the matter.
Thank you for your post. I have been looking into it and as you have mentioned, the RefreshSortPosition should not be called directly from the InitializeRecord event of the XamDataGrid. You can use the Dispatcher’s BeginInvoke method and since it is not causing any issues to your application, I can suggest using the solution that you have provided in your post.
Please let me know if you need any further assistance on the matter.