We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Problem in grouping using with nested tables

Hi, In gridGroupingControl, I am using nestedtables. This is working fine.But when I try to do the grouping it is not working properly. I am pasting code snippet to show how am I binding.. //Clear all auto populated columns before binding it to the grid GridTableDescriptor tableDescriptor = sfgAssetView.TableDescriptor; tableDescriptor.Columns.Clear();// don''yt clear these we''ll need them tableDescriptor.VisibleColumns.Clear(); tableDescriptor.GroupedColumns.Clear(); foreach(GridSummaryRowDescriptor rd in sfgAssetView.TableDescriptor.SummaryRows) rd.SummaryColumns.Clear(); tableDescriptor.SummaryRows.Clear(); tableDescriptor.SortedColumns.Clear(); tableDescriptor.ExpressionFields.Clear(); tableDescriptor.ResetSummaries(); srcDataSet.Relations.Add( srcDataSet.Tables[0].Columns[DBColumns.AssetId], srcDataSet.Tables[1].Columns[DBColumns.AssetId]); srcDataSet.Relations[0].RelationName = "AssetView_History"; gridGroupingControl.DataSource = srcDataSet.tables[0]; if (gridGroupingControl.TableModel.Table != null) { sfgAssetView.TableModel.Table.ResetRepaintElementsInQueue(); } this.gridGroupingControl.TableDescriptor.Columns.LoadDefault(); GridTableDescriptor tableDescriptor = this.sfgAssetView.TableDescriptor; //Adding it to visible column list this.gridGroupingControl.TableDescriptor.Columns.Add(ColDescriptor); this.gridGroupingControl.TableDescriptor.VisibleColumns.Add(ColDescriptor.Name); // Setting styles to the columns //setting grouping columns //setting frozen columns. when I load for the first time it works fine.The data displays correctly. After loading When I try to group by any field...I get a error in the this line : this.gridGroupingControl.TableDescriptor.Columns.LoadDefault(); - saying "object reference not set to an instance" Thanks, Prathima

5 Replies

AD Administrator Syncfusion Team August 4, 2005 09:37 AM UTC

>>When I try to group by any field...I get a error in the this line : this.gridGroupingControl.TableDescriptor.Columns.LoadDefault(); Why is your LoadDefault() call being hit when you try to group by? Shouldn''t every thing be set up before you add a col to the GroupedColumns collection?

PV Prathima Venkobachar August 4, 2005 09:59 AM UTC

We have a list of group by columns in the dropdown list. User can select the column that can be grouped. So everytime the user selects the groupby, Onchange of the dropdown value, we redo the binding and set the groupby columns. Basically our application is dynamic. The user can select/deselct the columns to be displayed in the grid. The user can select the columns to be grouped. The user can select the frozen columns. We are rebinding everytime the user changes any selection. Thanks, prathima

AD Administrator Syncfusion Team August 4, 2005 12:20 PM UTC

If all your user is doing is specifying a grouping without changing the datasource or displayed columns, then you might want to consider a having a path through your initialization code that just does the grouping in this case. Clearing columns and adding them back in is an overhead that serves no grid purpose in this case. Having a special path through your code would also probably avoid this problem you are seeing. I think it is being caused by this design feature of the grid. The grid delays actually performaing changes to things like the column collection until the next time the collection is actually accessed for some reason. So, in your case, you set enter your initialization code with an exisiting column setup. When the initialization code is completed, the final column setup is exactly the same as the one that it started with (since specifying a group does not affect the actual column collection.) So, one thing you can try is to explicitly access the collection before you are getting teh exception. So, right ahead of the LoadDefault call, add this line: int count = grid.TableDescriptor.Columns.Count; This should force the column collection to be reset. If it does not and count still comes back zero, then you can try manually adding the columns back to TabelDescriptor.Columns.

PV Prathima Venkobachar August 4, 2005 01:02 PM UTC

I am still getting count as zero. What do you mean by manually adding columns..? I should not do load default().. One more I have observed...firsttime when I load also the count comes zero but it works fine..I don''t get that error... Thanks, prathima

AD Administrator Syncfusion Team August 4, 2005 02:57 PM UTC

>>What do you mean by manually adding columns..? I mean calling TableDescriptor.Columns.Add to add the columns back in. What happens if you comment out you line that clears the columns. tableDescriptor.Columns.Clear(); but keep the other lines you have that clear the other collections?

Live Chat Icon For mobile
Up arrow icon