We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Changing filter conditions through code

Thread ID:





36637 Nov 4,2005 12:13 PM UTC Nov 4,2005 04:09 PM UTC WinForms 8
Tags: GridControl
Administrator [Syncfusion]
Asked On November 4, 2005 12:13 PM UTC

On a form, I have a combo box and a grouping grid. When the selected item in the combo box changes I want to update the view of the grouping grid. I do this by changing the filter condition like this TableDescriptor.RecordFilters[0].Conditions[0].CompareText = This works fine. However, after the filter has changed I also want to set the current record in the grid. I do this as follows Table.UnsortedRecords[position] = If I do this immediately after changing the filter condition, the grid will start to throw a lot of ArgumentOutOfRangeExceptions. I guess this is becase it has not finished updating its internal tables according to the new filter condition. To avoid this I tried to defer setting the new position to Application.Idle. That gets rid of the exceptions and the position is updated correctly. However, this also gives a lot of screen flickering because the grid will first scroll to the top and then back to the position that I set. Is there a better way to change both the filter and the position without any intermediate screen updates?

Administrator [Syncfusion]
Replied On November 4, 2005 12:31 PM UTC

Sorry, the two code lines above should be TableDescriptor.RecordFilters[0].Conditions[0].CompareText = "new filter"; GridRecord rec = gridMain.Table.UnsortedRecords[position] as GridRecord; if(rec != null) rec.SetCurrent();

Administrator [Syncfusion]
Replied On November 4, 2005 12:34 PM UTC

Try sandwiching the code between grid.BeginUpdate and grid.EndUpdate (maybe followed by grid.Refresh) to see if this will avoid this problem.

Administrator [Syncfusion]
Replied On November 4, 2005 01:12 PM UTC

That didn''t work. (After calling BeginUpdate the load went to 100 and the Application.Idle event was never raised.) Another solutions I have thought about, but haven''t found out how is to force the grid to update all its internal structures immediatly after setting the new filter. Then it might be possible to set the new position immediately without waiting for Application.Idle. Do you know a way to achieve this or any other solution?

Administrator [Syncfusion]
Replied On November 4, 2005 01:53 PM UTC

By default, when a filter is applied, the current record after the filter is the same as it was before the filter (provided that record is still visble - did not get filtered out). What is it that you are trying to do? Are you trying to set the currentrecord to some special record? If so, are you assured that this record is visible after the filter? (Checking if it is in the Table.FilteredRecords collection). This record not being visible may be what is causing the exceptions you are seeing. Here is a little sample doing something like you described. Can you see the problem in this sample? http://www.syncfusion.com/Support/user/uploads/GGC_Filter_a26ec614.zip

Administrator [Syncfusion]
Replied On November 4, 2005 02:10 PM UTC

After I change the filter the old current record is no longer visible. To use the standard customer order example: The form has combo with a list of customers. When the selected item in the customer combo change, I change the filter conditions to display the orders for the new customers. (Basically the grid is working like the child grid in a relation, but in my case there is no DataRelation to use so I try to achieve the same effect using the filter conditions.) The new orders are all different from the orders of the previous customer. After changing the filter I want to set the current record to a particular order. I have tried to solutions: 1. Update current record immedialtely after setting filter: Makes the grid start throwing exceptions. 2. Update the current record at Application.Idle. Works, but the grid moves the current record to the top first which causes screen flickering. It would be great if you can suggest a better solution.

Administrator [Syncfusion]
Replied On November 4, 2005 02:21 PM UTC

I think I found the solution which was actually quite simple. I update the current record (to the still not visible new record) before changing the filter conditions. This seems to work fine and the grid does not throw any exceptions.

Administrator [Syncfusion]
Replied On November 4, 2005 02:48 PM UTC

Here is a sample using the customer/orders from northwind. How do I see the problem in this sample? http://www.syncfusion.com/Support/user/uploads/CS_36bfc5bd.zip

Administrator [Syncfusion]
Replied On November 4, 2005 04:09 PM UTC

I can not see the problem in your sample. I am not sure why it works there and not in my case. Maybe it is related to the fact that my filter condition is more complicated. Anyway I was able to make my program work by moving SetCurrent() before setting the filter as explained above, so I think I will call it a day. Thanks for your help.


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon