I am trying to save and serialize settings for my RadGridView, without much luck. I want to preserve sorting, grouping, filtering, and row selection. I have tried versions 2011.2.712.35 (what we used previously) and 2012.2.725.35 (the latest), and haven't had much luck generally.
What's the best way to do this? Can you supply an example?
8 Answers, 1 is accepted
You can go to http://demos.telerik.com/wpf/ and launch the demos, then in the search box in the top-right corner type "GridView Serialization" and you should get the example that shows how to save and restore properties using our Persistence Framework.
All the best,
Ross
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

That seems to have solved my problem
(...although I haven't yet figured out why restoring causes my first column to jump several columns to the right, get wider, and start displaying a header.)
--Scott

HI,
I am new to Telerik ,I am using Radgridview R2 2107 version(2017.2.614.40) (WPF), I want to save gridview column position and load again when restart ,i have tries all examples which is posted but nothings worked for me... plz help

Hi,
still waiting for the rply...plz help...
Saving RadGridView column position is implemented in the GridViewSerialization SDK example. The columns' DisplayIndex property is saved in the ColumnProxy's DisplayOrder property.
Can you take a look at it and let me know if it works for you?
Additionally, you can read some more about the approach used in that example in the CustomPropertyProviders article in our documentation.
I am looking forward to your reply.
Regards,
Vladimir Stoyanov
Progress Telerik

Hi,
Thx for reply, i have used your example which works only when application is running ,once we close and restart application column shows at the actual position ,it is not showing at the position where user has dropped, we are using Datatable to display data,example which you have given that is on sufficient for me.plz help
This is expected since the RadGridView layout is saved in a memory stream which is lost when the application is closed. In order to store the layout after closing the application, you can use the IsolatedStorage like so:
private
void
Save(
object
sender, RoutedEventArgs e)
{
IsolatedStorageProvider isoProvider =
new
IsolatedStorageProvider();
isoProvider.SaveToStorage();
}
Then in the Loaded event of the RadGridView, you can load the layout:
private
void
gridView_Loaded(
object
sender, RoutedEventArgs e)
{var isoProvider =
new
IsolatedStorageProvider();
isoProvider.LoadFromStorage();
}Another option is to save the memory stream in a file and then load it from there.
I hope this helps. Don't hesitate to contact us again if you have any other questions.
Regards,
Vladimir Stoyanov
Progress Telerik

Hello,
I use the GridViewCustomPropertyProvider from the example to save/restore the column layout and filters also. This works fine for me.
But I have a column with dataType Nullable<Int32> and an user defined the "IsNotNull" filter. While restoring the grid-view settings the method gridView.FilterDescriptors.ResumeNotifications(); throws an ArgumentException with the message: "Operator 'IsNotNull' is incompatible with operand types 'Int32?' and 'OperatorValueFilterDescriptorBaseUnsetValue'". I tried to catch the exception, but the Application crashes with the callstack:
at Telerik.Windows.Data.Expressions.OperatorValueFilterDescriptorExpressionBuilderBase.CreateBodyExpressionThreadSafe()
at Telerik.Windows.Data.Expressions.FilterDescriptorCollectionExpressionBuilder.CreateBodyExpressionThreadSafe()
at Telerik.Windows.Data.Expressions.FilterDescriptorCollectionExpressionBuilder.CreateBodyExpressionThreadSafe()
at Telerik.Windows.Data.Expressions.FilterDescriptorCollectionExpressionBuilder.CreateBodyExpressionThreadSafe()
at Telerik.Windows.Data.Expressions.FilterExpressionBuilder.CreateFilterExpression()
at Telerik.Windows.Data.QueryableExtensions.Where(IQueryable source, CompositeFilterDescriptorCollection filterDescriptors)
at Telerik.Windows.Data.QueryableCollectionView.CreateView()
at Telerik.Windows.Data.QueryableCollectionView.CreateInternalList()
at Telerik.Windows.Data.QueryableCollectionView.get_InternalList()
at Telerik.Windows.Data.QueryableCollectionView.get_InternalCount()
at Telerik.Windows.Data.QueryableCollectionView.get_IsEmpty()
at Telerik.Windows.Controls.GridView.GridViewHeaderRow.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Controls.ScrollViewer.MeasureOverride(Size constraint)
at Telerik.Windows.Controls.GridView.GridViewScrollViewer.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Controls.Control.MeasureOverride(Size constraint)
at Telerik.Windows.Controls.GridView.GridViewDataControl.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Controls.Border.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Controls.Control.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Controls.DockPanel.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Documents.AdornerDecorator.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.ContextLayoutManager.UpdateLayout()
at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at Microsoft.Practices.CompositeUI.CabApplication`1.Run()
at ShellModuleLoader.Main(String[] arguments) in ModuleLoader.cs:line 122
Version of Telerik GridView tested: 2022.1.222 or 2023.1.315 (nuget-versions)
Best regards,
Patrick
This happens because at some point during the serialization the filter is set to FilterDescriptor.UnsetValue. At this specific moment the filter is deserializing and because the Int32? type doesn't match FilterDescriptor.UnsetValue, the exception is thrown. You should be able to avoid the error by adding the following if-condition when restoring the value filters:
if (setting.Filter1 != null)
{
columnFilter.FieldFilter.Filter1.Operator = setting.Filter1.Operator;
if (!(columnFilter.FieldFilter.Filter1.Operator == Telerik.Windows.Data.FilterOperator.IsNull |
columnFilter.FieldFilter.Filter1.Operator == Telerik.Windows.Data.FilterOperator.IsNotNull |
columnFilter.FieldFilter.Filter1.Operator == Telerik.Windows.Data.FilterOperator.IsEmpty |
columnFilter.FieldFilter.Filter1.Operator == Telerik.Windows.Data.FilterOperator.IsNotEmpty))
{
columnFilter.FieldFilter.Filter1.Value = setting.Filter1.Value;
}
columnFilter.FieldFilter.Filter1.IsCaseSensitive = setting.Filter1.IsCaseSensitive;
}
Hello Martin,
your solution works for me. Thank you very much.
Best regards,
Patrick