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

Null reference on clearing of templates or columns

1 Answer 141 Views
GridView
This is a migrated thread and some comments may be shown as answers.
gerbrand
Top achievements
Rank 2
gerbrand asked on 04 Jun 2009, 01:38 PM
Hello,

I keep getting this "error" in my log files:

4/06/2009 15:19:52: <<WARNING>> Column count: 4.
4/06/2009 15:19:52: <<WARNING>> NetworkManager.cs -> clear telerik columns:    at Telerik.WinControls.UI.TableViewDefinition.Measure(GridRowElement row, SizeF availableSize)
   at Telerik.WinControls.UI.GridTableElement.ArrangeOverride(SizeF finalSize)
   at Telerik.WinControls.RadElement.ArrangeCore(RectangleF finalRect)
   at Telerik.WinControls.RadElement.Arrange(RectangleF finalRect)
   at Telerik.WinControls.Layouts.ContextLayoutManager.UpdateLayout()
   at Telerik.WinControls.RadElement.UpdateLayout()
   at Telerik.WinControls.ComponentLayoutElementTree.GetPreferredSize(Size sizeConstraints)
   at Telerik.WinControls.RadControl.GetPreferredSize(Size proposedSize)
   at System.Windows.Forms.Layout.DefaultLayout.LayoutAutoSizedControls(IArrangedElement container)
   at System.Windows.Forms.Layout.DefaultLayout.xLayout(IArrangedElement container, Boolean measureOnly, Size& preferredSize)
   at System.Windows.Forms.Layout.DefaultLayout.LayoutCore(IArrangedElement container, LayoutEventArgs args)
   at System.Windows.Forms.Layout.LayoutEngine.Layout(Object container, LayoutEventArgs layoutEventArgs)
   at System.Windows.Forms.Control.OnLayout(LayoutEventArgs levent)
   at System.Windows.Forms.ScrollableControl.OnLayout(LayoutEventArgs levent)
   at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
   at System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.PerformLayout(IArrangedElement affectedElement, String affectedProperty)
   at System.Windows.Forms.Layout.LayoutTransaction.DoLayout(IArrangedElement elementToLayout, IArrangedElement elementCausingLayout, String property)
   at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
   at System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.PerformLayout(IArrangedElement affectedElement, String affectedProperty)
   at System.Windows.Forms.Layout.LayoutTransaction.DoLayout(IArrangedElement elementToLayout, IArrangedElement elementCausingLayout, String property)
   at System.Windows.Forms.Control.ControlCollection.Remove(Control value)
   at Telerik.WinControls.RadHostItem.PerformRoutedEventAction(RadElement sender, RoutedEventArgs args)
   at Telerik.WinControls.RadHostItem.OnTunnelEvent(RadElement sender, RoutedEventArgs args)
   at Telerik.WinControls.UI.RadTextBoxItem.OnTunnelEvent(RadElement sender, RoutedEventArgs args)
   at Telerik.WinControls.RadElement.RaiseTunnelEvent(RadElement sender, RoutedEventArgs args)
   at Telerik.WinControls.RadElement.SetParent(RadElement parent)
   at Telerik.WinControls.RadElement.ChangeCollection(RadElement child, ItemsChangeOperation changeOperation)
   at Telerik.WinControls.RadElementCollection.OnClear()
   at System.Collections.CollectionBase.Clear()
   at Telerik.WinControls.UI.GridRowElement.DisposeChildren(RadElementCollection children)
   at Telerik.WinControls.UI.GridRowElement.DisposeChildren(RadElementCollection children)
   at Telerik.WinControls.UI.GridRowElement.DisposeChildren(RadElementCollection children)
   at Telerik.WinControls.UI.GridRowElement.DisposeChildren(RadElementCollection children)
   at Telerik.WinControls.UI.GridRowElement.DisposeChildren(RadElementCollection children)
   at Telerik.WinControls.UI.GridRowElement.Dispose(Boolean disposing)
   at Telerik.WinControls.UI.GridTableHeaderRowElement.Dispose(Boolean disposing)
   at Telerik.WinControls.RadComponentElement.Dispose()
   at Telerik.WinControls.RadElement.Cleanup()
   at Telerik.WinControls.UI.GridTableBodyElement.CleanupRows()
   at Telerik.WinControls.UI.GridTableElement.Update(GridUINotifyAction action, GridViewRowInfo[] rowInfos)
   at Telerik.WinControls.UI.GridViewTemplate.UpdateUI(GridUINotifyAction action, GridViewRowInfo[] rowInfos)
   at Telerik.WinControls.Data.DataAccessComponent.ResetGrid()
   at Telerik.WinControls.Data.DataAccessComponent.UpdateColumns(NotifyCollectionChangedEventArgs e)
   at Telerik.WinControls.UI.GridViewTemplate.UpdateColumns(NotifyCollectionChangedEventArgs e)
   at Telerik.WinControls.UI.GridViewColumnCollection.NotifyListenersCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Telerik.WinControls.Data.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Telerik.WinControls.Data.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedAction action, Object item, Int32 index)
   at Telerik.WinControls.Data.ObservableCollection`1.RemoveItem(Int32 index)
   at Telerik.WinControls.Data.ItemObservableCollection`1.RemoveItem(Int32 index)
   at Telerik.WinControls.UI.GridViewColumnCollection.RemoveItem(Int32 index)
   at System.Collections.ObjectModel.Collection`1.RemoveAt(Int32 index)
   at adlogix.Views.NetworkManager.clearAdservedItemsColumns() in D:\networkManager\adlogix-views\Views\NetworkManager.cs:line 452, Object reference not set to an instance of an object..

the program doesn't crash, its just on this piece of code that I get the error message:

            if (rgvAllItems.MasterGridViewTemplate.Columns.Count > 0)  
            { 
                Log.LogMessageToFileWarnings("Column count: " + rgvAllItems.MasterGridViewTemplate.Columns.Count); 
                try  
                {  
                    while(rgvAllItems.MasterGridViewTemplate.Columns.Count > 0)  
                    {  
                        rgvAllItems.MasterGridViewTemplate.Columns.RemoveAt(0);  
                    }  
                      
                }catch(Exception ex)  
                {  
                    Log.LogMessageToFileWarnings(String.Format("NetworkManager.cs -> clear telerik columns: {0}, {1}", ex.StackTrace, ex.Message));  
                }  
            }  

before the while loop wasn't there and only existed with one line of code : rgvAllItems.MasterGridViewTemplate.Columns.Clear();

after some advice here on the forum to change it with the while loop I still got the same error message.
Strange thing is that the count of the columns is greater as zero so this should be giving any problems?

got the same message with this piece of code:
           
            if (rgvAllItems.MasterGridViewTemplate.ChildGridViewTemplates.Count > 0) 
            {
               
                try 
                { 
                    while (rgvAllItems.MasterGridViewTemplate.ChildGridViewTemplates.Count > 0) 
                    { 
                        rgvAllItems.MasterGridViewTemplate.ChildGridViewTemplates.RemoveAt(0); 
                    } 
                }catch (Exception ex) 
                { 
                    Log.LogMessageToFileWarnings( 
                        String.Format("NetworkManager.cs -> clear telerik ChildGridViewTemplates: {0}, {1}"
                                      ex.StackTrace, ex.Message)); 
                } 
            } 

just clearing the gridview for a rebind of other data, which is done without a problem. But I'm getting these errors in my log file on regular basis. So I'm curious what is happening since I have no idea If I'm doing something wrong here or not.

thanks in advanced





1 Answer, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 05 Jun 2009, 09:15 AM
Hi gerbrand,

I was not able to reproduce the issue with a simple test application. Maybe it is related to something specific in your application. You can try calling BeginUpdate and EndUpdate methods when removing columns:

rgvAllItems.GridElement.BeginUpdate(); 
while (rgvAllItems.MasterGridViewTemplate.Columns.Count > 0) 
    rgvAllItems.MasterGridViewTemplate.Columns.RemoveAt(0); 
rgvAllItems.GridElement.EndUpdate() 

Nevertheless, we want to investigate this issue further. Please send us your application, so we can test and locate this issue. I am looking forward to your reply.

Best wishes,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
gerbrand
Top achievements
Rank 2
Answers by
Jack
Telerik team
Share this question
or