This is a migrated thread and some comments may be shown as answers.

Column ReLoading Error

3 Answers 38 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Nick Anderson
Top achievements
Rank 1
Nick Anderson asked on 22 Dec 2009, 04:47 PM

I am getting an error trying to change my column collection after it has been previously loaded.
I am using as much of an MVVM approach as I can, to work around some of the gridview properties that aren't DependencyProperties i had to get a little creative. Everything was working fine, but it seems as if something in the last release(2009.3.1208.35) is causing an error.

I have a property in my ViewModel that is a GridViewColumnCollection. A multibinding converter is used to get the Columns property of the Grid and set it into the ViewModel( which is the Datacontext for the Grid)

My Grid is declared as such:

<telerik:RadGridView Name="gridviewRecordList" Margin="0,2,2,2" ScrollMode="RealTime" AutoGenerateColumns="False" IsReadOnly="True"  > 
                    <telerik:RadGridView.ItemsSource> 
                        <Binding Path="GetAllRecords" Mode="OneWay"/>  
                    </telerik:RadGridView.ItemsSource> 
                    <telerik:RadGridView.SelectedItem> 
                        <Binding Path="CurrentRecord"  Mode="Default"/>  
                    </telerik:RadGridView.SelectedItem> 
                    <telerik:RadGridView.ShowGroupPanel> 
                        <Binding Path="CurrentListToolView.IsGroupingAllowed" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged"  /> 
                    </telerik:RadGridView.ShowGroupPanel> 
                    <telerik:RadGridView.ShowColumnFooters> 
                        <Binding Path="CurrentListToolView.ShowColumnFooter" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" /> 
                    </telerik:RadGridView.ShowColumnFooters> 
                </telerik:RadGridView> 

Here's the Xaml for the column binding converter:

<Label.Content> 
                <MultiBinding> 
                    <MultiBinding.Converter> 
                        <local:ColumnConverter /> 
                    </MultiBinding.Converter> 
                    <Binding ElementName="gridviewRecordList" Path="DataContext" UpdateSourceTrigger="PropertyChanged"/>  
                    <Binding ElementName="gridviewRecordList" Path="Columns" UpdateSourceTrigger="PropertyChanged"/>  
                </MultiBinding> 
            </Label.Content> 
Here's ColumnConverter:
 If o IsNot Nothing And o.GetType.BaseType Is GetType(ASISplitWindowVM) And values.Count = 2 Then 
 
                    If values(1).GetType.BaseType Is GetType(GridViewColumnCollection) Then 
 
                        Dim columnColl As GridViewColumnCollection = CType(values(1), GridViewColumnCollection)  
                        Dim viewModel As ASISplitWindowVM = CType(o, ASISplitWindowVM)  
                        viewModel.ColumnList = columnColl  
                        viewModel.LoadListToolColumns()  
 
                    End If 
 
                End If 

The LoadListToolColumns Method reads through saved column data and creates GridViewDataColumns to add to the ColumnList Object(which since the ColumnList and the GridView.Columns are the same object it will update the UI when the ColumnList is changed).

This was all working fine, and still does work fine the first time it runs, but if I call LoadListToolColumns to try to load a different set of columns( after doing a ColumnList.Clear() ). Then I get an error, it works without error using version 2009.3.1103.35. 

This error is thrown after all my code has executed successfully:
System.NullReferenceException was unhandled  
  Message=Object reference not set to an instance of an object.  
  Source=Telerik.Windows.Controls.GridView  
  StackTrace:  
       at Telerik.Windows.Controls.GridView.GridViewCellsPanel.SetDataGridCellPanelWidth(IList children, Double newWidth)  
       at Telerik.Windows.Controls.GridView.GridViewCellsPanel.ArrangeOverride(Size arrangeSize)  
       at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)  
       at System.Windows.UIElement.Arrange(Rect finalRect)  
       at MS.Internal.Helper.ArrangeElementWithSingleChild(UIElement element, Size arrangeSize)  
       at System.Windows.Controls.ItemsPresenter.ArrangeOverride(Size arrangeSize)  
       at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)  
       at System.Windows.UIElement.Arrange(Rect finalRect)  
       at System.Windows.Controls.Grid.ArrangeOverride(Size arrangeSize)  
       at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)  
       at System.Windows.UIElement.Arrange(Rect finalRect)  
       at System.Windows.Controls.Control.ArrangeOverride(Size arrangeBounds)  
       at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)  
       at System.Windows.UIElement.Arrange(Rect finalRect)  
       at System.Windows.Controls.Grid.ArrangeOverride(Size arrangeSize)  
       at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)  
       at System.Windows.UIElement.Arrange(Rect finalRect)  
       at System.Windows.ContextLayoutManager.UpdateLayout()  
       at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)  
       at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()  
       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 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)  
       at System.Windows.Threading.DispatcherOperation.InvokeImpl()  
       at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)  
       at System.Threading.ExecutionContext.runTryCode(Object userData)  
       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)  
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)  
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)  
       at System.Threading.ExecutionContext.Run(ExecutionContext 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 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)  
       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)  
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)  
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)  
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)  
       at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)  
       at System.Windows.Threading.Dispatcher.Run()  
       at System.Windows.Application.RunDispatcher(Object ignore)  
       at System.Windows.Application.RunInternal(Window window)  
       at System.Windows.Application.Run(Window window)  
       at System.Windows.Application.Run()  
       at MainUI.Application.Main() in C:\Documents and Settings\nicka.ASICSLOCAL\My Documents\Visual Studio 2010\Projects\Oasis 2010\Oasis\MainUI\obj\Debug\Application.g.vb:line 77  
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)  
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)  
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()  
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)  
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)  
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)  
       at System.Threading.ThreadHelper.ThreadStart()  
  InnerException:   
 

Any ideas?

3 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 28 Dec 2009, 09:00 AM
Hi Nick Anderson,

I have prepared a small dummy project in order to reproduce the exception you are getting. I have simulated your architecture with two buttons. Each one of them clear the columns and then adds some columns to the collection.

Unfortunately, I was unable to get the exception that you have described. Can you please take my sample project and modify it so it reproduces the behavior that you are experiencing. Alternatively, you can create a new dummy project that reproduces the exception and attach it, if that would be easier for you. Our goal is to be able to get the exception on our end so that we can debug it and track down what is causing it.

Thanks in advance. We are looking forward to hearing from you.

Regards,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Nick Anderson
Top achievements
Rank 1
answered on 23 Feb 2010, 06:47 PM
I was able to resolve my issue by not calling Clear() on my GridViewColumnCollection, but instead looping through the collection and removing each column. The exception wasn't being thrown when Clear() was called, it was being thrown after all my user code seemed to have executed, maybe when it was trying to redraw?

0
Vlad
Telerik team
answered on 24 Feb 2010, 09:16 AM
Hi,

Can you send us an example (via support ticket) where we can reproduce the original problem?

Sincerely yours,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
Nick Anderson
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Nick Anderson
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or