ok..
i am 99% successful in creating a grid with columns added dynamically from database. the reason for this is so that when our data feeds get extended, we don't have to deploy code with column definitions etc, we can just add some metadata in a table and it appears in our grids.
the problem is as follows. i can re-create the columns on INIT. but sometimes, i need the grid to use viewstate, and so, after INIT the columns get re-created from postback and i need to override them again from database.
in order to avoid adding the columns twice, i call this.Columns.Clear() before re-adding them.
if the grid is in OutlookGroupBy mode, i get the exception below. this leads me to beleive that this.columns.Clear() does not wipe all the information completely. something is still there and blows up with null exception. again this happens on 2nd postback with outlookGroupBy layout enabled.
exception:
[NullReferenceException: Object reference not set to an instance of an object.] Infragistics.WebUI.UltraWebGrid.GroupByColumnComparer.Compare(Object x, Object y) +165 System.Array.BinarySearch(Array array, Int32 index, Int32 length, Object value, IComparer comparer) +229[InvalidOperationException: Failed to compare two elements in the array.] System.Array.BinarySearch(Array array, Int32 index, Int32 length, Object value, IComparer comparer) +289 System.Collections.SortedList.IndexOfKey(Object key) +31 System.Collections.SortedList.get_Item(Object key) +15 Infragistics.WebUI.UltraWebGrid.UltraGridLayout.RegisterGroupByColumn(UltraGridColumn groupedColumn) +26 Infragistics.WebUI.UltraWebGrid.UltraWebGrid.GroupRows(RowsCollection rows, UltraGridColumn column) +321 Infragistics.WebUI.UltraWebGrid.UltraWebGrid.SortGroupRows(RowsCollection rows) +314 Infragistics.WebUI.UltraWebGrid.UltraWebGrid.PerformGroupRows() +186 Infragistics.WebUI.UltraWebGrid.DBBinding.BindList(IEnumerable datasource) +1275 Infragistics.WebUI.UltraWebGrid.DBBinding.DataBind(Object dataSource, String dataMember) +860 Infragistics.WebUI.UltraWebGrid.UltraWebGrid.DataBind() +405
so i guess what i am asking here is, how can i do a clean column clear and re-add
did some research, and it appears that the following code should have fixed my issue:
this.ResetBands(); this.ResetColumns(); this.ResetRows();
unfortunately it didn't. i am using grid version 8.2
The error does not happen on DataBind anymore, but i still get the same error on following types of calls:
col.SortIndicator = SortIndicator.None;andGrid.DisplayLayout.Bands[0].Columns[0].IsGroupByColumn = false;
error:
null reference at:Infragistics.WebUI.UltraWebGrid.GroupByColumnComparer.Compare(Object x, Object y) +165 System.Array.BinarySearch(Array array, Int32 index, Int32 length, Object value, IComparer comparer) +229
I am using V10.3.
The above code worked in Version 8.1 but not in Version 10.3.
For version 10.3,
grid.Reset(); will do the trick.