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

RadGridView available filter conditions

1 Answer 198 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 25 Jul 2012, 02:57 PM
In my grid, I want to limit the available filter conditions as they don't apply. I am doing so in the ContextMenuOpening event:

Private Sub WorkLogGridView_ContextMenuOpening(sender As Object, e As ContextMenuOpeningEventArgs) Handles WorkLogGridView.ContextMenuOpening
            If e.ContextMenuProvider IsNot Nothing Then
                e.ContextMenu.Items.Remove(e.ContextMenu.Items.Single(Function(item) item.Text = "Contains"))
                e.ContextMenu.Items.Remove(e.ContextMenu.Items.Single(Function(item) item.Text = "Does not contain"))
                e.ContextMenu.Items.Remove(e.ContextMenu.Items.Single(Function(item) item.Text = "Starts with"))
                e.ContextMenu.Items.Remove(e.ContextMenu.Items.Single(Function(item) item.Text = "Ends with"))
                e.ContextMenu.Items.Remove(e.ContextMenu.Items.Single(Function(item) item.Text = "Is null"))
                e.ContextMenu.Items.Remove(e.ContextMenu.Items.Single(Function(item) item.Text = "Is not null"))
                e.ContextMenu.Items.Remove(e.ContextMenu.Items.Single(Function(item) item.Text = "Custom"))
              End If
        End Sub

This works correctly. However, note that I am removing the first default item "Contains". Even though it is removed, it is the default condition selected:
http://screencast.com/t/vFv78ZoLE

This shows that the items have been removed correctly:
http://screencast.com/t/tcotptFmN4aK

Ideally I would like either No filter or Equals selected by default instead of Contains.

In addition, I'd like this functionality to be different for different columns. I'm trying to find how to determine which column is applicable in the code above, but am not able to find the needed info. I've also tried to subscribe to the CurrentColumnChanged, ColumnIndexChanged, and ColumnIndexChanging event to stored the selected column but it appears those events do not fire when I click on the filter button. 

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 30 Jul 2012, 07:00 AM
Hi Jason,

Your question has already been answered in the support thread you've opened. We kindly ask you to use just one support channel to contact us. Posting the same questions numerous times slows down our response time because we will need to review and address two or more tickets instead of one. Moreover threads are handled according to license and time of posting, so if it is an urgent problem, we suggest you use a support ticket, which would be handled before a forum thread.

Thank you for your understanding.

I am copying my answer here so the community can benefit from it:

Removing the items from the context menu has nothing to do with the filter cell text and this is why it is not changed. The text depends on the FilterDescriptor applied to the column. Here is how you can apply the desired filters to the column with no value: 
Imports Telerik.WinControls.Data
  
Public Class Form1
    Public Sub New()
        InitializeComponent()
  
        Dim r As New Random()
        Dim table As New DataTable()
        table.Columns.Add("ID", GetType(Integer))
        table.Columns.Add("Name", GetType(String))
        table.Columns.Add("Bool", GetType(Boolean))
  
        For i As Integer = 0 To 9
            table.Rows.Add(i, "Row " & i, If(r.[Next](10) > 5, True, False))
        Next
  
        Me.RadGridView1.DataSource = table
  
  
        RadGridView1.EnableFiltering = True
  
        RadGridView1.Columns(0).FilterDescriptor = New FilterDescriptor(Nothing, FilterOperator.None, Nothing)
        RadGridView1.Columns(1).FilterDescriptor = New FilterDescriptor(Nothing, FilterOperator.IsEqualTo, Nothing)
  
    End Sub
End Class

In order to get the clicked column, you can do that by checking the ColumnInfo property of the clicked filter cell in the ContextMenuOpening event handler: 
Private Sub radGridView1_ContextMenuOpening(sender As Object, e As ContextMenuOpeningEventArgs) Handles RadGridView1.ContextMenuOpening
  
        Dim filterCell As GridFilterCellElement = TryCast(e.ContextMenuProvider, GridFilterCellElement)
If filterCell IsNot Nothing Then
        RadMessageBox.Show("The clicked column is: " + filterCell.ColumnInfo.Name)
End If
  
 
End Sub


Regards,
Stefan
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Tags
GridView
Asked by
Jason
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or