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

Setting ItemSource to null

5 Answers 213 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 21 Jan 2011, 10:17 PM
After I've updated to latest version, I've recieved a null reference exception when I was setting the RadGridView's ItemSource to null.
I've rolled back to the previous version of Telerik Controls and it is back to normal.  Could you check the new version for a possible bug?

5 Answers, 1 is accepted

Sort by
0
Yordanka
Telerik team
answered on 24 Jan 2011, 01:45 PM
Hi Artel,

Could you send the exception StackTrace ? We were unable to reproduce it locally. 

Kind regards,
Yordanka
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Jason
Top achievements
Rank 1
answered on 02 Feb 2011, 05:41 PM
I apologize for the delay.  Occurs in the RadPanelBar_Selected event where I set the ItemSource of the RadGridView depending on the selected menu item.  I set the ItemSource to null to clear it then populate it with the selected table.  NullReferenceException is thrown when I set the ItemSource to null.  Again works fine with version 2010.3.1110.35 but I receive an exception with version 2010.3.1314.35.

   at CST.UI.Windows.MainWindow.ItemsGrid_DataLoaded(Object sender, EventArgs e) in C:\Documents and Settings\[user]\My Documents\Visual Studio 2010\Projects\[Project]\[Project]\UI.Windows\MainWindow.xaml.cs:line 369
   at Telerik.Windows.Controls.GridView.GridViewDataControl.OnDataLoaded(EventArgs e)
   at Telerik.Windows.Controls.GridView.GridViewDataControl.LoadData()
   at Telerik.Windows.Controls.GridView.GridViewDataControl.OnItemsCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Data.DataItemCollection.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Data.DataItemCollection.ClearItemsSource()
   at Telerik.Windows.Controls.GridView.GridViewDataControl.<>c__DisplayClass18.<Bind>b__17()
   at Telerik.Windows.Controls.CursorManager.PerformTimeConsumingOperation(FrameworkElement frameworkElement, Action action)
   at Telerik.Windows.Controls.GridView.GridViewDataControl.Bind(Object newValue)
   at Telerik.Windows.Controls.GridView.GridViewDataControl.OnItemsSourceChanged(Object oldValue, Object newValue)
   at Telerik.Windows.Controls.DataControl.OnItemsSourcePropertyChanged(DependencyObject origin, DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, OperationType operationType)
   at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, OperationType operationType, Boolean isInternal)
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at Telerik.Windows.Controls.DataControl.set_ItemsSource(Object value)
   at CST.UI.Windows.MainWindow.RadPanelBar_Selected(Object sender, RadRoutedEventArgs e) in C:\Documents and Settings\[user]\My Documents\Visual Studio 2010\Projects\[Project]\[Project]\UI.Windows\MainWindow.xaml.cs:line 215
0
Vlad
Telerik team
answered on 03 Feb 2011, 07:46 AM
Hi,

 Can you post the code of the RadGridView DataLoaded event handler? 

Kind regards,
Vlad
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Jason
Top achievements
Rank 1
answered on 03 Feb 2011, 03:51 PM
private void ItemsGrid_DataLoaded(object sender, EventArgs e)
        {
           //Get list of column headers in display order
            var columnNames = ColumnOrderHelper.GetColulmns(_selectedTable.Name);     
            int counter = 0;
  
            if (!_isFiltering && !_isSorting)
            {
                foreach (var columnName in columnNames)
                {
                    ItemsGrid.Columns[columnName].DisplayIndex = counter++;
                }
            }
                    
            //Determine what CRUD actions can be taken by the user
            var authService = new AuthorizationService();
            DeletesEnabled = authService.CanPerformAction(_selectedTable.Name, this.Role, Privilege.Delete);
            EditsEnabled = authService.CanPerformAction(_selectedTable.Name, this.Role, Privilege.WriteExisting);
            InsertsEnabled = authService.CanPerformAction(_selectedTable.Name, this.Role, Privilege.AddNew);
  
            ItemsGrid.ShowInsertRow = InsertsEnabled;
  
            var xaml = "<DataTemplate><TextBlock Text=\"{Binding " + columnNames[0] + "}\"/></DataTemplate>";
            var sr = new MemoryStream(Encoding.ASCII.GetBytes(xaml));
            var pc = new ParserContext();
            pc.XmlnsDictionary.Add("", "http://schemas.microsoft.com/winfx/2006/xaml/presentation");
            pc.XmlnsDictionary.Add("x", "http://schemas.microsoft.com/winfx/2006/xaml");
  
            ItemsGrid.ScrollPositionIndicatorTemplate = (DataTemplate)XamlReader.Load(sr, pc);           
        }
0
Vlad
Telerik team
answered on 03 Feb 2011, 04:05 PM
Hi,

 Can you comment temporary setting of DisplayIndex to see what will be the result? 

Regards,
Vlad
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
GridView
Asked by
Jason
Top achievements
Rank 1
Answers by
Yordanka
Telerik team
Jason
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or