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

ColumnGroups.Add produces null reference exception

0 Answers 27 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Matthew Kruczek
Top achievements
Rank 1
Matthew Kruczek asked on 10 Oct 2012, 02:50 PM
The following piece of code...

this.DataGrid.ColumnGroups.Clear();
 
var groupColumnDef = new GridViewColumnGroup();
                    groupColumnDef.Header = column.Title;
                    groupColumnDef.Name = column.Title.GetColumnName();
                    groupColumnDef.HeaderStyle = this.Resources["s1"] as Style;
                    groupColumnDef.HeaderTemplate = this.Resources["GroupHeader"] as DataTemplate;
 
                    // Add the group
                 
                        // The current column is top level so just add it
                        if (!this.DataGrid.ColumnGroups.Contains(groupColumnDef))
                            this.DataGrid.ColumnGroups.Add(groupColumnDef);

Produces the following error..

base {System.NullReferenceException: Object reference not set to an instance of an object.
   at Telerik.Windows.Controls.GridView.CommonHeaderPresenter.ArrangeLowestHeaders()
   at Telerik.Windows.Controls.GridView.CommonHeaderPresenter.ArrangeHeaders()
   at Telerik.Windows.Controls.GridView.CommonHeaderPresenter.PlaceCommonHeaders()
   at Telerik.Windows.Controls.GridView.CommonHeaderPresenter.Rearrangeheaders()
   at Telerik.Windows.Controls.GridView.CommonHeaderPresenter.NotifyCellsPropertyChanged(DependencyObject d, String propertyName, DependencyPropertyChangedEventArgs e, UpdateTarget target)
   at Telerik.Windows.Controls.GridView.GridViewHeaderRow.NotifyPropertyChanged(DependencyObject d, String propertyName, DependencyPropertyChangedEventArgs e, UpdateTarget target)
   at Telerik.Windows.Controls.GridView.GridViewDataControl.NotifyPropertyChanged(DependencyObject d, String propertyName, DependencyPropertyChangedEventArgs e, UpdateTarget target)
   at Telerik.Windows.Controls.GridViewColumnCollectionInternal.CalculateColumnWidths(Object arg)} System.Exception {System.NullReferenceException}

Any thoughts as to why?

No answers yet. Maybe you can help?

Tags
GridView
Asked by
Matthew Kruczek
Top achievements
Rank 1
Share this question
or