Trouble clearing a filter of a View object

Trouble clearing a filter of a View object

Post by VGhvbWFzIE » Thu, 23 Aug 2007 21:34:01


The code below fails to clear the filter of the view object. After calling
Apply(), the Filter property is reset to its original value as it was before
the assignment vw.Filter= "". So if I first enter a value in the
_SearchCombo, it applies the Filter correctly. After clearing the text of the
_SearchCombo, the code runs and assign an empty string to the Filter. After
calling Apply, the value is reset to the value before that assignment.

Am I overlooking something obvious?

Regards,

Thomas.

Outlook.View vw = instance.ActiveExplorer().CurrentView as
Outlook.View;
if ( String.IsNullOrEmpty( _SearchCombo.Text ) )
vw.Filter = "";
else
vw.Filter = String.Format(
"\" http://www.yqcomputer.com/ \" LIKE '%{0}%'",
_SearchCombo.Text );
vw.Apply();
 
 
 

Trouble clearing a filter of a View object

Post by Ken Slovak » Thu, 23 Aug 2007 23:04:36

If you look at the Object Browser Help for Apply you will see it recommends
using view.Reset before using view.Apply if you are changing an existing
view. If you are creating a new view you would use view.Save before using
view.Apply.

See if that helps.

--
Ken Slovak
[MVP - Outlook]
http://www.yqcomputer.com/
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.yqcomputer.com/

 
 
 

Trouble clearing a filter of a View object

Post by VGhvbWFzIE » Thu, 23 Aug 2007 23:34:03

Hi Ken,

Thanks for trying to help out.


No, that doesn't help. Calling Reset before setting the Filter doesn't make
any difference in behaviour. Well, actually it does change something. It now
changes the visible dates to today only, instead of the dates I had selected.

What doesn't make sense to me is that setting a *new* Filter works as
expected, but setting the Filter to an empty string doesn't.

Regards,

Thomas.

This is the code I used:

Outlook.View vw = instance.ActiveExplorer().CurrentView as
Outlook.View;
vw.Reset();
if ( String.IsNullOrEmpty( _SearchCombo.Text ) )
vw.Filter = "";
else
vw.Filter = String.Format(
"\" http://www.yqcomputer.com/ \" LIKE '%{0}%'",
_SearchCombo.Text );

vw.Apply();
 
 
 

Trouble clearing a filter of a View object

Post by Ken Slovak » Sat, 25 Aug 2007 22:01:25

Reset will set the filter back to its defaults, so I'd expect the selected
date would change in that case, as will any other custom settings.

Offhand I'm not sure why it's not working for you, I almost never use the
Filter clause directly that way. I usually get the view XML and work
directly with that, where I create/modify/delete any filters I want to apply
to a view.

--
Ken Slovak
[MVP - Outlook]
http://www.yqcomputer.com/
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.yqcomputer.com/