This is a migrated thread and some comments may be shown as answers.

Disable Filtering on specific columns with AutoGenerate columns

5 Answers 150 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stephen
Top achievements
Rank 1
Stephen asked on 02 Oct 2008, 01:49 PM
Hi,

I have created a CrossTab routine which populates a RadGrid.  I always no there will be a "Project" column in the first column, but the rest are generated as crosstabs based on the date criteria.

I need to enable filtering on the Projet column, but remove it programatically from all other columns.

How do I do this?

I tried capturing the column in PreRender and looking for col.AllowFiltering but this doesnt appear to be an option?

Thanks

i

5 Answers, 1 is accepted

Sort by
0
Stephen
Top achievements
Rank 1
answered on 03 Oct 2008, 03:00 PM
Lets see if I can prompt a response ;-)

Can this snippet from the documentation be adjusted to "hide" a filter text box an image?  I am looking to disable the filter text boxes on autogenerated columns (but leave them there in the first column which is always fixed in terms of what it returned).  I know I can set the individual columns in design mode to allow filtering...how to do it at run time!?



Protected Sub RadGrid1_ItemCreated(sender As Object, e As GridItemEventArgs) Handles RadGrid1.ItemCreated
   If TypeOf e.Item Is GridFilteringItem Then
      Dim filteringItem As GridFilteringItem = CType(e.Item, GridFilteringItem)

      'set dimensions for the filter textbox
      Dim box As TextBox = CType(filteringItem("ContactName").Controls(0), TextBox)
      box.Width = Unit.Pixel(30)
      'set ImageUrl which points to your custom image
      Dim image As Image = CType(filteringItem("ContactName").Controls(1), Image)
     image.ImageUrl = "<my_image_url>"
   End If
End Sub 'RadGrid1_ItemCreated
0
Stephen
Top achievements
Rank 1
answered on 05 Oct 2008, 09:29 AM
Hi,

Thanks.  I am now getting:

MESSAGE : Unable to cast object of type 'Telerik.WebControls.GridExpandColumn' to type 'Telerik.WebControls.GridBoundColumn'.\nSOURCE:



Thanks

i


Protected Sub grdDemandCost_By_QTR_ColumnCreated(ByVal sender As Object, ByVal e As Telerik.WebControls.GridColumnCreatedEventArgs) Handles grdDemandCost_By_QTR.ColumnCreated

If Session("ddDemandCost_Project") = "(All)" Then

If Not (e.Column.IsBoundToFieldName("Project")) Then

CType(e.Column, GridBoundColumn).AllowFiltering = False

End If

Else

If Not (e.Column.IsBoundToFieldName("Activity")) Then

CType(e.Column, GridBoundColumn).AllowFiltering = False

End If

End If

End Sub

0
Vladimir
Top achievements
Rank 1
answered on 05 Oct 2008, 12:57 PM
Hi Stephen,

Not all grid columns are GridBoundColumn! You may need to check if the grid column is GridBoundColumn before casting,

Vlad
0
Stephen
Top achievements
Rank 1
answered on 05 Oct 2008, 02:07 PM

Done...thanks.  Although I dont undestand why I have an expand column being created in a non-hierarchical grid ;-)

Protected
Sub grdDemandCost_By_QTR_ColumnCreated(ByVal sender As Object, ByVal e As Telerik.WebControls.GridColumnCreatedEventArgs) Handles grdDemandCost_By_QTR.ColumnCreated

If TypeOf e.Column Is GridBoundColumn Then

 

If Session("ddDemandCost_Project") = "(All)" Then

 

If Not (e.Column.IsBoundToFieldName("Project")) Then

 

CType(e.Column, GridBoundColumn).AllowFiltering = False

 

End If

 

Else

 

If Not (e.Column.IsBoundToFieldName("Activity")) Then

 

CType(e.Column, GridBoundColumn).AllowFiltering = False

 

End If

 

End If

 

End If

 

End Sub

Tags
Grid
Asked by
Stephen
Top achievements
Rank 1
Answers by
Stephen
Top achievements
Rank 1
Vladimir
Top achievements
Rank 1
Share this question
or