Home - Forums-.NET - FlyGrid.Net (Windows Forms) - FilterMode options

FlyGrid.Net (Windows Forms)

.NET Datagrid - Fast, highly customizable, industry standards .NET data grid control for WinForms

This forum related to following products: FlyGrid.Net

FilterMode options
Link Posted: 06-Nov-2006 05:41
Are there any examples for Custom FilterModes?  I want to remove the options [Blanks] and [NonBlanks]
Link Posted: 06-Nov-2006 05:48
You can find a sample of custom filter in the \"Filters and Summaries\" example of the Demo - open this example and expand some node to see the nested grid, in the nested grid click to filter indicator of the [Order Date] column.
Link Posted: 06-Nov-2006 06:09
I see the example, it's a shame that when I select on of the Filters (Only 1994 year) I get the following fatal exception:

Link Posted: 06-Nov-2006 06:14
is this FlyGrid.Net v1.4.1?
If not - please download latest (v.1.4.1) version.
Link Posted: 06-Nov-2006 06:24
Ok, I will get the latest version.  However I have looked at the sample code and I don't think it does easily what I want to do.  

I want to use the existing automatic FilterMode options (whereby each unique type in the column's data is automatically added to the filtering options) and I just want to remove [Blanks] & [NonBlanks] from that list.
Link Posted: 06-Nov-2006 06:30
[quote="NineRays"]is this FlyGrid.Net v1.4.1?
If not - please download latest (v.1.4.1) version.


The error was received using v1.4.1
Link Posted: 06-Nov-2006 06:54
here is a sample:
[c#]
private void InitGrid(FlyGrid grid)
{
  //connect to ColumnFilterValidate event
  grid.ColumnFilterValidate += new ColumnFilterListValidateHandler(ColumnFilterValidate);
}

//Apply our own filters list to the Order Date column.
private void ColumnFilterValidate(object sender, Column column, ArrayList filterList)
{
  if (column.Caption == \"Order Date\")
  {
    filterList.Clear();
    DateTime end93 = new DateTime(1993, 12, 31);
    DateTime end94 = new DateTime(1994, 12, 31);
    DateTime end95 = new DateTime(1995, 12, 31);
    DateTime end96 = new DateTime(1996, 12, 31);
    FilterItem[] in94Year= new FilterItem[] {
          new FilterItem(end93.ToShortDateString(), FilterOperator.And, ConditionOperator.GreaterThan),
          new FilterItem(end94.ToShortDateString(), FilterOperator.And, ConditionOperator.LessThanOrEqual)
      };
    FilterItem[] in95Year= new FilterItem[] {
          new FilterItem(end94.ToShortDateString(), FilterOperator.And, ConditionOperator.GreaterThan),
          new FilterItem(end95.ToShortDateString(), FilterOperator.And, ConditionOperator.LessThanOrEqual)
      };
    FilterItem[] in96Year= new FilterItem[] {
          new FilterItem(end95.ToShortDateString(), FilterOperator.And, ConditionOperator.GreaterThan),
          new FilterItem(end96.ToShortDateString(), FilterOperator.And, ConditionOperator.LessThanOrEqual)
      };
    filterList.Add(new FilterHelper(\"[All]\", FilterMode.All));
    filterList.Add(new FilterHelper(\"[Custom]\", FilterMode.Custom));
    filterList.Add(new FilterHelper(\"Only 1994 year\", in94Year));
    filterList.Add(new FilterHelper(\"Only 1995 year\", in95Year));
    filterList.Add(new FilterHelper(\"Only 1996 year\", in96Year));
  }
}
Link Posted: 06-Nov-2006 11:34
I've corrected example to prevent code from exception mentioned:
[c#]
private void InitGrid(FlyGrid grid)
{
  //connect to ColumnFilterValidate event
  grid.ColumnFilterValidate += new ColumnFilterListValidateHandler(ColumnFilterValidate);
}

private void ColumnFilterValidate(object sender, Column column, ArrayList filterList)
{
  if (column.Caption == \"Order Date\")
  {    
    filterList.Clear();
    DateTime end93 = new DateTime(1993, 12, 31);
    DateTime end94 = new DateTime(1994, 12, 31);
    DateTime end95 = new DateTime(1995, 12, 31);
    DateTime end96 = new DateTime(1996, 12, 31);
    CultureInfo ivCulture = CultureInfo.InvariantCulture;
    FilterItem[] in94Year= new FilterItem[] {
      new FilterItem(end93.ToString(ivCulture.DateTimeFormat.ShortDatePattern, ivCulture), FilterOperator.And, ConditionOperator.GreaterThan),
      new FilterItem(end94.ToString(ivCulture.DateTimeFormat.ShortDatePattern, ivCulture), FilterOperator.And, ConditionOperator.LessThanOrEqual)
    };
    FilterItem[] in95Year= new FilterItem[] {
      new FilterItem(end94.ToString(ivCulture.DateTimeFormat.ShortDatePattern, ivCulture), FilterOperator.And, ConditionOperator.GreaterThan),
      new FilterItem(end95.ToString(ivCulture.DateTimeFormat.ShortDatePattern, ivCulture), FilterOperator.And, ConditionOperator.LessThanOrEqual)
    };
    FilterItem[] in96Year= new FilterItem[] {
      new FilterItem(end95.ToString(ivCulture.DateTimeFormat.ShortDatePattern, ivCulture), FilterOperator.And, ConditionOperator.GreaterThan),
      new FilterItem(end96.ToString(ivCulture.DateTimeFormat.ShortDatePattern, ivCulture), FilterOperator.And, ConditionOperator.LessThanOrEqual)
    };
    filterList.Add(new FilterHelper(\"[All]\", FilterMode.All));
    filterList.Add(new FilterHelper(\"[Custom]\", FilterMode.Custom));
    filterList.Add(new FilterHelper(\"Only 1994 year\", in94Year));
    filterList.Add(new FilterHelper(\"Only 1995 year\", in95Year));
    filterList.Add(new FilterHelper(\"Only 1996 year\", in96Year));
  }
}
Link Posted: 06-Nov-2006 21:19
Yes thank you for the code copied from the example app.  However as stated this example does not do what I want.  I don't want to completely build the filter options from scratch.

I have many columns that need to be filtered, and all I want to do is remove the options [Blanks] and [NonBlanks].

It would be good to be able to exclude these through the designer.

Your code builds the filter list everytime the filter button is clicked on, is this what happens behind the scenes with normal filtering.  Is there some way to get data list of the column clicked at this point?

Say normal filtering gave me a filtered list as:

[All]
[Blanks]
[NonBlanks]
[GBP]
[USD]
[AUD]

I would want my filter list to look like:

[All]
[GBP]
[USD]
[AUD]

Seems simple, no?
Link Posted: 08-Nov-2006 08:44
You can override Column.GetFilterList method to remove [Blanks] and [NonBlanks] options:
[c#]
public class CustomFilterColumn : Column
{
  public CustomFilterColumn(string caption) : base(caption){}
  protected override object[] GetFilterList(FlyGridViewPort port)
  {
    ArrayList filterList = new ArrayList(base.GetFilterList (port));
    bool blanksRemoved = false, nonBlanksRemoved =  false;
    for(int i=0; i < filterList.Count; i++)
    {
      FilterHelper fh = filterList[i] as FilterHelper;
      if (fh != null && fh.Value is FilterMode)
      {
        FilterMode mode = (FilterMode)fh.Value;
        if (mode == FilterMode.Blanks)
        {
          filterList.RemoveAt(i);
          blanksRemoved = true;
          i--;
        }
        else if (mode == FilterMode.NonBlanks)
        {
          filterList.RemoveAt(i);
          nonBlanksRemoved = true;
          i--;
        }
        //stop when both option removed
        if (blanksRemoved && nonBlanksRemoved)
          break;
      }
    }
    return filterList.ToArray();
  }
}