I have a RADGrid that requires that it's columns get removed and replaced per the context under which the data is being loaded. When the grid first loads, the Grouping operation runs fine. However, when the context changes and the Grid structure is reinitialized, when I try to group by any column I get the GridGroupByException: Expression cannot be null or empty error.
I start out with a Radgrid without column definitions. When the page loads, I invoke a procedure that first clears the Grids grouping, context menu, data binding and column settings then it runs an initialization routine to configure the grid for the data that will be loaded.
Here's the code for the ClearGridSettings method that's run first:
Here's the code for the first Intialization:
Here's the initialization code for the context change that's causing the error:
As you can see by the commented out section I tried to explicitly set GridGroupByFields but that didn't work either. I also tried setting the GroupByExpression on a column by column basis with the same result.
What am I missing?
I start out with a Radgrid without column definitions. When the page loads, I invoke a procedure that first clears the Grids grouping, context menu, data binding and column settings then it runs an initialization routine to configure the grid for the data that will be loaded.
Here's the code for the ClearGridSettings method that's run first:
Private Sub ClearGridSettings() ' - Clear Grouping/Sort Levels ' - Clear Context Menus ' - Clear Data Bindings ' - Clear Columns With grdSubmission 'Clear Grouping/Sort Levels .MasterTableView.GroupByExpressions.Clear() .MasterTableView.SortExpressions.Clear() 'Clear Context Menus .ClientSettings.ClientEvents.OnRowContextMenu = "" 'Clear Data Bindings .DataSource = "" .DataBind() 'Clear Columns .Columns.Clear() End With End SubHere's the code for the first Intialization:
Private Sub InitializeSubmissionGrid(ByVal GridViewSchema As Int16) '########################################## 'Initialize Data Grid for Submission Claims Review ' - Reset Grid ' - Get GridView Schema for Submissions Claim Listing ' - Implement Column Structure ' - Set Miscellaneous Parameters '########################################### ClearGridSettings() 'Get Grid View Schema for Submissions View Dim objDW As New DWGlobals Dim ds As DataSet = objDW.GetGridViewSchema(GridViewSchema) With grdSubmission 'Add Columns to Grid For Each objRow As DataRow In ds.Tables(0).Rows Dim objCol As New GridBoundColumn() .MasterTableView.Columns.Add(objCol) objCol.DataField = objRow("ColName") objCol.HeaderText = objRow("ColName") If Not IsDBNull(objRow("FormatString")) Then objCol.DataFormatString = objRow("FormatString") End If objCol = Nothing Next ' Set Miscellaneous parameters .ClientSettings.Resizing.AllowResizeToFit = True .ClientSettings.Resizing.AllowColumnResize = True .ClientSettings.Scrolling.AllowScroll = True .ClientSettings.Scrolling.UseStaticHeaders = True .AutoGenerateColumns = False .MasterTableView.GroupsDefaultExpanded = False .MasterTableView.GridLines = GridLines.Both .MasterTableView.AllowFilteringByColumn = False .MasterTableView.Caption = txtSubmLabel.Text & "...(Claim Qty: " & txtClaimQty.Text & " )" End WithEnd SubHere's the initialization code for the context change that's causing the error:
Private Sub InitializeFindingsGrid(ByVal GridViewSchema As Int16) '########################################## 'Initialize Data Grid for Validation Findings Review ' - Reset Grid ' - Get GridView Schema for Validation Findings Listing ' - Implement Column Structure ' - Set Miscellaneous Parameters '########################################### ClearGridSettings() 'Get Grid View Schema for Submissions View Dim objDW As New DWGlobals Dim ds As DataSet = objDW.GetGridViewSchema(GridViewSchema) objDW = Nothing Dim exp As New GridGroupByExpression() Dim gbf As New GridGroupByField() With grdSubmission 'Add Columns to Grid For Each objRow As DataRow In ds.Tables(0).Rows Dim objCol As New GridBoundColumn() objCol.DataField = objRow("ColName") objCol.HeaderText = objRow("ColName") objCol.UniqueName = objRow("ColName") If Not IsDBNull(objRow("FormatString")) Then objCol.DataFormatString = objRow("FormatString") End If objCol.GroupByExpression = objRow("ColName") 'Add GroupByField to GroupByExpression 'gbf = New GridGroupByField 'With gbf ' .FieldName = objRow("ColName") ' .HeaderText = objRow("ColName") ' .HeaderValueSeparator = " HeaderValSep " ' .Aggregate = GridAggregateFunction.Count 'End With 'exp.SelectFields.Add(gbf) .MasterTableView.Columns.Add(objCol) objCol = Nothing Next 'Add GroupByExpression object to table ' .MasterTableView.GroupByExpressions.Add(exp) ' Set Miscellaneous parameters .ClientSettings.Resizing.AllowResizeToFit = True .ClientSettings.Resizing.AllowColumnResize = True .ClientSettings.Scrolling.AllowScroll = True .ClientSettings.Scrolling.UseStaticHeaders = True .AutoGenerateColumns = False .MasterTableView.GroupsDefaultExpanded = False .MasterTableView.GridLines = GridLines.Both .MasterTableView.AllowFilteringByColumn = False .MasterTableView.Caption = "Findings For " & txtSubmLabel.Text & _ "...( " & txtFindingType.Text & ")" 'Enable Grid Options for Findings Review .AllowMultiRowSelection = True .ClientSettings.Selecting.AllowRowSelect = True .ClientSettings.Selecting.EnableDragToSelectRows = True .ClientSettings.ClientEvents.OnRowContextMenu = "RowContextMenu" End With exp = Nothing gbf = Nothing End SubAs you can see by the commented out section I tried to explicitly set GridGroupByFields but that didn't work either. I also tried setting the GroupByExpression on a column by column basis with the same result.
What am I missing?