Problem with Grouping the second time

rated by 0 users
This post has 7 Replies | 5 Followers

Top 500 Contributor
Points 355
ygalanter Posted: 08-18-2008 10:20 AM

Hi, I am having problems when setting group-by columns in code. Here is a small snippet from InitializeLayout event:

oColumn = uwgGrid.Columns.FromKey(sColumnKey)
oColumn.SortIndicator = iSortIndicator
oColumn.IsGroupByColumn = True

I take several columns from the grid, set their sorting (ascending/descending) and set their IsGroupByColumn property to true (this adds the column to SortedColumns collection).

It works fine the first time, the groups are displayed properly. But when I do the same procedure the second time (same resultset is returned from database, same code executes in InitializeLayput event, same colums are used for grouping) I am getting error:

"Failed to compare two elements in the array."

Stack trace:

   at System.Array.BinarySearch(Array array, Int32 index, Int32 length, Object value, IComparer comparer)
   at System.Collections.SortedList.IndexOfKey(Object key)
   at System.Collections.SortedList.get_Item(Object key)
   at Infragistics.WebUI.UltraWebGrid.UltraGridLayout.RegisterGroupByColumn(UltraGridColumn groupedColumn)
   at Infragistics.WebUI.UltraWebGrid.UltraWebGrid.GroupRows(RowsCollection rows, UltraGridColumn column)
   at Infragistics.WebUI.UltraWebGrid.UltraWebGrid.SortGroupRows(RowsCollection rows)
   at Infragistics.WebUI.UltraWebGrid.UltraWebGrid.PerformGroupRows()
   at Infragistics.WebUI.UltraWebGrid.DBBinding.BindList(IEnumerable datasource)
   at Infragistics.WebUI.UltraWebGrid.DBBinding.DataBind(Object dataSource, String dataMember)
   at Infragistics.WebUI.UltraWebGrid.UltraWebGrid.DataBind()

 Inner exception:

"Object reference not set to an instance of an object."

Stack trace:

at Infragistics.WebUI.UltraWebGrid.UltraGridLayout.GroupByColumnComparer.Compare(Object x, Object y)
at System.Array.BinarySearch(Array array, Int32 index, Int32 length, Object value, IComparer comparer)

I've tried to clear the grid completely before the second call, as well as clearing SortedColumns collection - it doesn't help. I am using NetAdvantage 2006 Vol. 3 CLR 2.0.

Any help is greatly appreciated.

  • | Post Points: 20
Not Ranked
Points 65

You may need to reset the columns, rows and bands.  For example:

UltraWebGrid1.ResetBands()

UltraWebGrid1.ResetColumns()

UltraWebGrid1.ResetRows()

 

 

 

  • | Post Points: 55
Top 500 Contributor
Points 355

THANKS!

That did the trick ;)

  • | Post Points: 5
Top 500 Contributor
Points 355

After uprading to 2009.1 for CLR2.0 (with hotfix 2013) the error started to happen again. So far I've been unsuccessful in solving it. Any help is appreciated.

  • | Post Points: 20
Not Ranked
Points 110

I am experiencing the same issue, despite calling WebGrid.ResetBands(), WebGrid.ResetColumns() and WebGrid.ResetRows() before binding the WebGrid.  Is there a fix for  this issue yet?

 

  • | Post Points: 20
Not Ranked
Points 100

Normal 0 false false false MicrosoftInternetExplorer4

I did not encounter "Failed to compare two elements in the array." until I started using ResetBands(), ResetColumns(), & ResetRows(). So I tried to solve the grouping on rebind problem without them.

 

I discovered that grouping occurs only when the value of IsGroupByColumn changes from False to True. If it is already true before the DataBind() then no grouping occurs when PerformGroupRows() is called a second time (bug?).

 

UltraWebGrid1.DataBind()

UltraWebGrid1.Columns.FromKey("MyGroupingColumn").IsGroupByColumn = False

UltraWebGrid1.Columns.FromKey("MyGroupingColumn").IsGroupByColumn = True

UltraWebGrid1.PerformGroupRows()

UltraWebGrid1.ExpandAll(True)

  • | Post Points: 20
Not Ranked
Points 200

Thank you so much - I was having the same problem. 

Setting all the IsGroupBys to false before rebinding, and then setting them to true again where appropriate stopped my crashing!

  • | Post Points: 20
Not Ranked
Points 145

Hi,

I am also getting the same error. Can anybody suggest a solution for this. I have done all the above suggested. 

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Failed to compare two elements in the array.

This is the error i am getting while second time grouping.

  

 

  • | Post Points: 5
Page 1 of 1 (8 items) | RSS

Forum Statistics

40,788 users have contributed to 129,818 threads and 144,150 posts.

In the past week, we've had 5,572 new users, adding to our total of 467,617 registered users!

In the past 24 hours, we have 56 new thread(s), 217 new post(s), and

In the past 3 days, the most popular thread for everyone has been "Google Chrome & UltraWebGrid. Compatible or Not? ". The post with the most views is "In wingrid RowFilter dropdown items for DropDown column is not shwing ". The most replies were made to "Google Chrome & UltraWebGrid. Compatible or Not? ".

Please welcome our newest member fceskxv .