Filtering

Posts   
 
    
Posts: 54
Joined: 22-Jun-2010
# Posted on: 29-Jul-2010 07:54:05   

Dear Support,

I wrote a functiona as follows to load the grid and later on to filter the same based on text entered by user in textbox. Problem is, though I have set the filter, it is loading all the records. Not sure what is going wrong

public void PopulateGrid() { var adapteraccountnature = new DataAccessAdapter(); var datasourceaccountnature = new EntityCollection<AccountnatureEntity>(new AccountnatureEntityFactory()); adapteraccountnature.FetchEntityCollection(datasourceaccountnature, null); var accountnatureview = new EntityView2<AccountnatureEntity>(datasourceaccountnature);

        IPredicateExpression AccountNatureFilter = new PredicateExpression();
        AccountNatureFilter.Add(AccountnatureFields.Flag == StandardFlag.recordvalidflag);
        AccountNatureFilter.Add(new FieldLikePredicate(AccountnatureFields.Description, null, "Solution%"));
        accountnatureview.Filter = AccountNatureFilter;

        dgridaccountnature.DataSource = datasourceaccountnature;
    }
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 29-Jul-2010 08:19:15   
            dgridaccountnature.DataSource = accountnatureview;
Posts: 54
Joined: 22-Jun-2010
# Posted on: 29-Jul-2010 09:01:36   

Walaa wrote:

            dgridaccountnature.DataSource = accountnatureview;

Great. So I am on right track. Just one small help. Now on textbox change event, If i want to filter the same view in textchange event, what is the right way of doing it Sir.

In Grid Load I wrote like this which works fine public void PopulateGrid() { var adapteraccountnature = new DataAccessAdapter(); var datasourceaccountnature = new EntityCollection<AccountnatureEntity>(new AccountnatureEntityFactory()); adapteraccountnature.FetchEntityCollection(datasourceaccountnature, null); IEntityView2 customerView = datasourceaccountnature.DefaultView; IPredicateExpression filter = new PredicateExpression(AccountnatureFields.Flag == StandardFlag.recordvalidflag); filter.Add(new FieldLikePredicate(AccountnatureFields.Description, null, "S%")); customerView.Filter = filter; dgridaccountnature.DataSource = customerView;

    }

Now on text change event, I wrote as follows

var datasourceaccountnature = new EntityCollection<AccountnatureEntity>(new AccountnatureEntityFactory()); IEntityView2 customerView = datasourceaccountnature.DefaultView; IPredicateExpression filter = new PredicateExpression(AccountnatureFields.Flag == StandardFlag.recordvalidflag); filter.Add(new FieldLikePredicate(AccountnatureFields.Description, null, "C%")); customerView.Filter = filter;

Grid load works fine** but text change event does not change to C%**

And if I add dgridaccountnature.DataSource = customerView; in textchange event i get error Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function.

If am able to solve this, this solves most my problems in my project

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 29-Jul-2010 09:23:13   
Now on text change event, I wrote as follows

var datasourceaccountnature = new EntityCollection<AccountnatureEntity>(new AccountnatureEntityFactory());
            IEntityView2 customerView = datasourceaccountnature.DefaultView;
            IPredicateExpression filter = new PredicateExpression(AccountnatureFields.Flag == StandardFlag.recordvalidflag);
            filter.Add(new FieldLikePredicate(AccountnatureFields.Description, null, "C%"));
            customerView.Filter = filter;

I understand that you want to re-filter (in memory) the exiting collection on the TextChanged event, but in the above code, you have used a new collection which is not fetched from the database, so there are no entities to filter.

shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 29-Jul-2010 09:43:13   

.

Posts: 54
Joined: 22-Jun-2010
# Posted on: 29-Jul-2010 09:56:03   

Walaa wrote:

Now on text change event, I wrote as follows

var datasourceaccountnature = new EntityCollection<AccountnatureEntity>(new AccountnatureEntityFactory());
            IEntityView2 customerView = datasourceaccountnature.DefaultView;
            IPredicateExpression filter = new PredicateExpression(AccountnatureFields.Flag == StandardFlag.recordvalidflag);
            filter.Add(new FieldLikePredicate(AccountnatureFields.Description, null, "C%"));
            customerView.Filter = filter;

I understand that you want to re-filter (in memory) the exiting collection on the TextChanged event, but in the above code, you have used a new collection which is not fetched from the database, so there are no entities to filter.

You got it perfectly right sir. I want re-filter (in memory) the exiting collection on the TextChanged event. So am stuck here as to how to write. Your little help here will speed up my project

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 29-Jul-2010 09:59:53   

Use the pre-fetched collection, don't instantiate a new one. You may keep it in the scope of your dialog/window class, to be re-used again.

Posts: 54
Joined: 22-Jun-2010
# Posted on: 29-Jul-2010 12:02:09   

Thanks everything is fine now