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.
Unfortunately, activation email could not send to your email. Please try again.

Changing filter conditions through code

Thread ID:

Created:

Updated:

Platform:

Replies:

36637 Nov 4,2005 07:13 AM Nov 4,2005 11:09 AM Windows Forms 8
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On November 4, 2005 07:13 AM

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 07:31 AM

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 07:34 AM

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 08:12 AM

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 08:53 AM

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 09:10 AM

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 09:21 AM

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 09:48 AM

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 11:09 AM

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.

CONFIRMATION

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.

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.

;