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> |
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?