Hi Everyone,
I got a problem in Rad Grid -
Scenario: I have got a grid that displays 5-10 columns. In the same page I have provided user with checkboxes so that they can either hide or display the columns based on whether the checkboxes are selected or not. There is no problem hiding column but when displaying back the hidden column, I have to call rebind() method of radGrid to display the column back. Due to this, collasping feature is not working. All this is performed in PreRender method which is called everytime when the checkbox is ticked or unticked (auto postback = true for checkbox)
Please any sort of help is appreciated.
Code snippet:
Protected Sub gridExpenditure_PreRender(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gridExpenditure.PreRender
Dim availalbleCols As New List(Of String)
availalbleCols.Add("Business")
availalbleCols.Add("Brand")
availalbleCols.Add("ConsumerActivityName")
availalbleCols.Add("ConsumerActivityID")
availalbleCols.Add("Vendor")
availalbleCols.Add("Supplier")
availalbleCols.Add("Media")
availalbleCols.Add("MarketingPlanName")
availalbleCols.Add("Material")
availalbleCols.Add("CostElement")
Dim selectedCols As New List(Of String)
Dim unSelectedCols As New List(Of String)
Dim i As Integer
For i = 0 To cbAvailableCols.Items.Count - 1
If cbAvailableCols.Items(i).Selected = False Then
unSelectedCols.Add(cbAvailableCols.Items(i).Value)
Else
selectedCols.Add(cbAvailableCols.Items(i).Value)
End If
Next
'Set visible to false for missing Columns only
If Not unSelectedCols.Count = 0 Then
Dim gridCol As GridColumn
For Each gridCol In gridExpenditure.MasterTableView.RenderColumns
Dim colName As String
For Each colName In unSelectedCols
If gridCol.UniqueName = colName Then
gridCol.Visible = False
End If
Next
Next
End If
'Set visible to true for rest of the columns
If Not selectedCols.Count = 0 Then
Dim gridCol As GridColumn
For Each gridCol In gridExpenditure.MasterTableView.RenderColumns
Dim colName As String
For Each colName In selectedCols
If gridCol.UniqueName = colName Then
gridCol.Visible = True
'Calling rebind avoids collapse feature but it is needed when user wants to add column :(
'Need to fix this somehow...
gridExpenditure.Rebind()
End If
Next
Next
End If
End Sub
Thanks a lot.
Sincerely,
Milan G