Home - Forums-.NET - FlyGrid.Net (Windows Forms) - Custom Filter List doesnt work.

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

Custom Filter List doesnt work.
Link Posted: 04-Jul-2007 23:29
Hi,

I spent an hour trying to make it work. Can you please have a look - what is wrong with it. Grid version is 1.5.2.0


void flyGrid1_ColumnFilterValidate(object sender, Column column, System.Collections.ArrayList filterList)
{
    CultureInfo ivCulture = CultureInfo.InvariantCulture;

    if (column.FieldName == \"col1\")
    {
        filterList.Clear();
        filterList.Add(new FilterHelper(\"[All]\", FilterMode.All));
        filterList.Add(new FilterHelper(\"[Custom]\", FilterMode.Custom));

        List dates = new List();
        foreach(Node node in flyGrid1.Rows.Items)
        {
            DateTime date = ((DateTime)node.GetCellValue(0)).Date;
            if (!dates.Contains(date))
            {
                dates.Add(date);

                filterList.Add(new FilterHelper(date.ToShortDateString(),
                    new FilterItem[]
                    {
                    new FilterItem(date           , FilterOperator.And, ConditionOperator.GreaterThanOrEqual),
                    new FilterItem(date.AddDays(1), FilterOperator.And, ConditionOperator.LessThan)
                    }));

            }
        }
    }
}

. . .

this.dateTimeColumn1.AllowFiltering = true;
this.dateTimeColumn1.Caption = \"Date\";
this.dateTimeColumn1.FieldName = \"col1\";
this.dateTimeColumn1.ImageKey = null;
this.dateTimeColumn1.MaxValue = new System.DateTime(9999, 12, 31, 23, 59, 59, 999);
this.dateTimeColumn1.MinValue = new System.DateTime(((long)(0)));
this.dateTimeColumn1.State = NineRays.Windows.Forms.Grids.ColumnState.DropDownBtnUp;
this.dateTimeColumn1.Width = 120;



Custom filter string is : [col1] >= #06/07/2007 00:00:00# AND ([col1] < #07/07/2007 00:00:00#)

But it has no effect on the grid data - all rows are the same with filter or without.
Link Posted: 18-Sep-2007 02:30
up...

I need this answered ASAP! We paid for the license and I cant get an answer for 3 months now!
Link Posted: 20-Sep-2007 05:10
Are you sure using the data bound mode?

I've just tested your code.
Have few modifications for it to work.
Using the following data:

DataTable data = new DataTable();
data.Columns.Add(\"col1\", typeof(DateTime));
data.Rows.Add(new DateTime(2007, 12, 12));
data.Rows.Add(new DateTime(2005, 12, 12));
data.Rows.Add(new DateTime(1995, 12, 12));

flyGrid1.Rows.DataSource = data;


And the following filter function (is almost same as yours):


filterList.Clear();
filterList.Add(new FilterHelper(\"[All]\", FilterMode.All));
filterList.Add(new FilterHelper(\"[Custom]\", FilterMode.Custom));

List dates = new List();


foreach (NodeBase node in flyGrid1.Rows.Items)
{
    object cellValue = node.GetCellValue(0);
    if (cellValue != null)
    {
        DateTime date = ((DateTime)cellValue).Date;
        if (!dates.Contains(date))
        {
            dates.Add(date);

            filterList.Add(new FilterHelper(date.ToShortDateString(),
                new FilterItem[]
                {
                new FilterItem(date           , FilterOperator.And, ConditionOperator.GreaterThanOrEqual),
                new FilterItem(date.AddDays(1), FilterOperator.And, ConditionOperator.LessThan)
                }));

        }
    }
}


And everything works as it should.
Link Posted: 20-Sep-2007 22:09
sorry for misleading. It was second post in a row in argument with Victor who disappeared few months ago.

This is not bound grid. Custom filters works with a bound grid - I know - I used your sample code for that.

Unbound grid doesnt filter although I can see red arrow indicating it is being filtered but has no effect on actual rows (all are displayed).

We add rows as grid.Rows.Items.Add(new Node(new object[] { . . . } ));
Link Posted: 20-Sep-2007 22:14
Here is a quote from my email to Victor on 6th of July:

I got your demo code for this and watered it down and found that your demo works only if you bind to DataTable, if you bind to List or if you run data in unbound mode (like get data from DataTable OrderDetails and put it into a row - grid.Rows.Items.Add(new Node(new object []....) then it stops to work....
Link Posted: 22-Sep-2007 05:55
Yes, FlyGrid will not filter data when bound to List or something else.
The core reason is that it uses ADO.NET data filtering features.
Link Posted: 25-Sep-2007 21:45
cool. but would you agree that if you had stated that the product supports a feature (custom filtering in this case) then it should be provided. If there are conditions to apply (to be bound to a specific object type) then it has to be in the 'terms and conditions' and it should be reasonable (which is not because data binding to ado.net objects doesnt look reasonable). therefore this is a bug.

hence my question - when 9Rays is going to fixt it?

thank you
Link Posted: 25-Sep-2007 23:40
Yes, the filtering info should be more clean in the FlyGrid documentation.
And we will definitely fix this.
Definitely, we'll also schedule custom filtering option,

As for your case, I think using the datatable to store and bind data is the best way for your case. ADO.NET filtering capabilities provide the fastest way to sort/filter data.

You can easily create datatable with data you need and bind it to FlyGrid, so you'll have fastest filtering/sorting functionality since it uses native ADO code.

From one side, it looks like a workaround, but in a closer look, it is the most appropriate way to work with bound data when it comes to filtering/sorting feature.
Link Posted: 26-Sep-2007 00:33
You can also override FlyGrid.GetFilter method in order to provide your own custom filtering functions. But from my point of view, DataTable is the fastest  and easier way.
Link Posted: 27-Sep-2007 04:23
I agree with you but our project is rolling out next month and unbound mode was in spec so my personal opinion cannot change the fact.

Can you please expand on GetFilter ? just few lines of code to illustrate the idea.

Thank you