zneak
zneak

Reputation: 138141

Is there a way to filter UltraGrids based on the value of 2 columns?

Say I have an Infragistic UltraGrid with columns Foo and Bar. Is it possible to filter the table so that only rows where Foo and Bar are not equal are displayed?

For instance, if I had this data:

Foo  Bar
--------
0.1  0.1
0.1  0.2
0.2  0.2

The filter would hide the first and the third row.

Upvotes: 4

Views: 9179

Answers (3)

Dmitriy Konovalov
Dmitriy Konovalov

Reputation: 1817

It is simplier than it seems and i am sure you do not have to create additional column or something:

UltraGridColumn fooColumn = Grid.DisplayLayout.Bands[0].Columns["Foo"];
UltraGridColumn barColumn = Grid.DisplayLayout.Bands[0].Columns["Bar"];
ColumnFilter fooColumnFilter = fooColumn.Band.ColumnFilters[fooColumn];
fooColumnFilter.ClearFilterConditions();
fooColumnFilter.FilterConditions.Add(FilterComparisionOperator.NotEquals, barColumn);

Upvotes: 5

alhalama
alhalama

Reputation: 3228

Since you are not allowing users to toggle this filter and are using a DataTable, the simplest solution is to filter the DataTable rather than the grid.

For example if your DataTable is fooData you would use the follwoing:

fooData.DefaultView.RowFilter = "Foo <> Bar";

Upvotes: 1

Dour High Arch
Dour High Arch

Reputation: 21722

You should be able to do this from the Grid designer;

  1. Create a new Boolean column with Formula [Foo]!=[Bar] to your data source.
  2. Add the hidden column to your grid and set your grid's DisplayLayout.Override.RowFilterMode = RowFilterMode.AllRowsInBand.
  3. In the grid.DisplayLayout.Band[].ColumnFilters, add a new FilterLogicalOperator.And with the new column's FilterConditions.Add(FilterComparisionOperator.Equals, true).

Upvotes: 1

Related Questions