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

FIlter Gridview column on another column

1 Answer 210 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Barry
Top achievements
Rank 1
Barry asked on 19 Nov 2010, 09:29 AM
Hi 

I would like to be able to filter my gridview based on the the value of two columns.

So as an example I have a grid view containing two Amount columns and I'd like to implement filtering so that they could filter the results based on any one of the following criteria: 

  • Amount 1 > Amount 2
  • Amount 2 > Amount 1
  • Amount 1 = Amount 2

Is this possible to do?  I am using 2009 Q2 and am unable to upgrade to the latest version.

Thanks

1 Answer, 1 is accepted

Sort by
0
Accepted
Julian Benkov
Telerik team
answered on 24 Nov 2010, 12:44 PM
Hi Barry,

This functionality cannot be achieved directly by a FilterDescriptor object. First, you must calculate the value of the desired column and then use this value to add a FilterDescriptor. Here is a sample code snippet:

private void radButton1_Click(object sender, EventArgs e)
{
    this.radGridView1.EnableFiltering = true;
 
    object val = this.radGridView1.Evaluate("Max(Amount2)", this.radGridView1.Rows);
    this.radGridView1.FilterDescriptors.Add(new FilterDescriptor("Amount1", FilterOperator.IsGreaterThan, val));
}

You can also achieve the desired behavior by using the custom filtering mode that RadGridView provides.
Please review the examples of this mode in our Examples application, section RadGridView >> Filtering.

Regards,
Julian Benkov
the Telerik team
Get started with RadControls for WinForms with numerous videos and detailed documentation.
Tags
GridView
Asked by
Barry
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Share this question
or