Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
332
XamWebGrid.Columns.add() throw NullReference exception.
posted

Hi,

I have a single xamwebgrid. I am getting data from different table on button click, since datasource is changing at run time so I am adding columns using code xamwebgrid.columns.add().

When I bind the data first time everything is working fine, but as I bind the grid with other datasource (or with the same datasource), xamwebgrid.columns.add() throw NullReferenceException with message "Object reference is not set to an instance of object" and stacktrace is as follow:

   at Infragistics.Controls.Grids.RowsManager.InvalidatePager()
   at Infragistics.Controls.Grids.RowsManager.InvalidateData()
   at Infragistics.Controls.Grids.RowsManagerBase.OnColumnLayoutPropertyChanged(ColumnLayout layout, String propertyName)
   at Infragistics.Controls.Grids.RowsManager.OnColumnLayoutPropertyChanged(ColumnLayout layout, String propertyName)
   at Infragistics.Controls.Grids.XamGridRowsManager.OnColumnLayoutPropertyChanged(ColumnLayout layout, String propertyName)
   at Infragistics.Controls.Grids.RowsManagerBase.OnColumnLayoutPropertyChanged(Object sender, PropertyChangedEventArgs e)
   at Infragistics.DependencyObjectNotifier.OnPropertyChanged(String propertyName)
   at Infragistics.Controls.Grids.ColumnLayout.InvalidateData()
   at Infragistics.Controls.Grids.ColumnBaseCollection.AddItem(Int32 index, ColumnBase item)
   at Infragistics.Collections.CollectionBase`1.Add(T item)
   at SBOSLCollection.Grid.EntityClass.GoodReciptPoListData.AddColumns()

My code to rebind the datagrid and add columns is as follow:

grid.ItemSource=null;

grid.Columns.Clear();

BaseColumn column= new TextColumn();

column.headerText="Title Column";

column.key="ColumnKey";

grid.columns.add(column); //Here Nullreference exception is throw.