Reputation: 262
I've got a RadGrid with programmatically generated columns, including a variable number of column groups. Each of the column groups contains four columns, two that are displayed and two that are not.
Above the RadGrid I have a series of checkboxes, one for each column group. The goal is to have the user check or uncheck the boxes depending on what columns they wish to see. Currently I am setting the columns' Display properties when a checkbox's checked value is changed by using radgrid.Columns.FindByUniqueName("columnName").Display
. However the column group itself cannot be accessed this way. As it is, the column groups disappear when all their child columns disappear, but they do not reappear when their child columns are displayed, causing the headers to become misaligned.
Relevant code:
'Defining the grid
Dim radgrid As RadGrid
radgrid = New RadGrid()
Dim i as Integer = 0
For Each r As DataRow In subTable.Rows
Dim colGroup As GridColumnGroup = New GridGroupColumn()
radgrid.MasterTableView.ColumnGroups.Add(colGroup)
colGroup.HeaderText = r.Item("Name")
colGroup.Name = "colGroup" & i
Dim colID As GridBoundColumn = New GridBoundColumn()
radgrid.MasterTableView.Columns.Add(colID)
colID.ColumnGroupName = "colGroup" & i
colID.DataField = "id" & i
colID.HeaderText = "ID"
colID.UniqueName = "id" & i
colID.Display = False
Dim colScore As GridBoundColumn = New GridBoundColumn()
radgrid.MasterTableView.Columns.Add(colScore)
colScore.ColumnGroupName = "colGroup" & i
colScore.DataField = "score" & i
colScore.HeaderText = "Score"
colScore.UniqueName = "score" & i
i += 1
Next
'Checkbox CheckedChanged sub
If selectedButton.Checked = True Then
radgrid.Columns.FindByUniqueName("colScore" & selectedButton.Value.ToString()).Display = True
Else
radgrid.Columns.FindByUniqueName("colScore" & selectedButton.Value.ToString()).Display = False
End If
Ideally I'd like to do something like radgrid.MasterTableView.ColumnGroups.FindGroupByName("colGroup" & selectedButton.Value.ToString()).Display = False
but there is no Display
property for that and the Visible
property is ReadOnly. I've also tried re-setting the ColumnGroupName
of the columns after setting them to display, but that also does not work.
I'm guessing the fact that I have hidden columns is what's making this more complicated than it should be, but is there a way to get this to work with hidden columns?
Upvotes: 0
Views: 4828
Reputation: 262
The solution actually turned up when I was working on a somewhat unrelated issue.
Calling radgrid.Rebind()
after changing the value of the Display
property causes the group column headers to disappear and reappear as desired.
Protected Sub button_CheckChanged()
If selectedButton.Checked = True Then
radgrid.Columns.FindByUniqueName("colScore" & selectedButton.Value.ToString()).Display = True
Else
radgrid.Columns.FindByUniqueName("colScore" & selectedButton.Value.ToString()).Display = False
End If
radgrid.Rebind()
End Sub
Upvotes: 1