I am new to WPF and Infragistics. I have a small WPF project with a XamGrid and a filter. I want to remove the equals operand from the filter list for one of the columns in the grid. I found this code online from the Infragistics forums:
FilterColumnSettings fcs =
this.MyDataGrid.Columns.DataColumns["ProductID"].FilterColumnSettings;
fcs.RowFilterOperands.Remove(ComparisonOperator.Equals);
Which is supposed to do just that, but I cannot get it to work. When my application loads up, the equals filter option is still there. Am I calling the code from the wrong place? This is what I have written:
public MainWindow()
{
InitializeComponent();
FilterColumnSettings fcs = this.xamGrid.Columns.DataColumns["ProductID"].FilterColumnSettings;
fcs.RowFilterOperands.Remove(ComparisonOperator.Equals);
}
And this is my XamGrid in my XAML code:
<ig:XamGrid
x:Name="xamGrid"
ItemsSource="{Binding}"
ColumnWidth="*"
AutoGenerateColumns="False" >
<ig:XamGrid.FilteringSettings>
<ig:FilteringSettings AllowFiltering="FilterRowTop" />
</ig:XamGrid.FilteringSettings>
<ig:XamGrid.Columns>
<ig:TextColumn Key="ProductID" HeaderText="Product ID" />
</ig:XamGrid.Columns>
</ig:XamGrid>
Any help would be appreciated!
EDIT: When I added in the filter, I kept getting the following error:
System.NullReferenceException: 'Object reference not set to an instance of an object.' Infragistics.Controls.Grids.ReadOnlyKeyedColumnBaseCollection.this[string].get returned null.
To overcome this error, I followed the solution from this link: https://www.infragistics.com/community/forums/f/retired-products-and-controls/29815/allowfilterrow-top-infragistics-silverlight-requireemptyconstructorexception and the solution that worked for me is as follows:
this.xamGrid.DataObjectRequested += new EventHandler<DataObjectCreationEventArgs>(xamGrid_DataObjectRequested);
public void xamGrid_DataObjectRequested(object sender, DataObjectCreationEventArgs e)
{
if (e.ObjectType == typeof(DataRowView))
{
DataTable dt = new DataTable();
DataRow r = dt.NewRow();
dt.Rows.Add(r);
DataRowView drv = dt.DefaultView[dt.Rows.IndexOf(r)];
e.NewObject = drv;
}
}
This allowed me to use the filtering option in the XamGrid but could this be causing my issue with changing the filter operands?
Thanks!