Skip to main content
Home Forums Silverlight Programming WCF RIA Services FilterDescriptor returns null
8 replies. Latest Post by vitorcastelo on November 9, 2009.
(0)
vitorcas...
Member
0 points
5 Posts
11-06-2009 2:46 PM |
Hi all,
I have a ComboBox with three options that defines which operator should be used with a FilterDescriptor. That FilterDescriptor is linked to a DatePicker. I'm trying to do that in code-behind, but with any luck so far.
In my XAML file I have the following code:
<riaControls:DomainDataSource x:Name="dds" AutoLoad="True" QueryName="Query" LoadSize="20">
<riaControls:DomainDataSource.FilterDescriptors> <riaData:FilterDescriptorCollection>
<riaData:FilterDescriptor x:Name="filter1" PropertyPath="Date" > <riaData:ControlParameter ControlName="dtpDate" RefreshEventName="SelectedDateChanged" /> </riaData:FilterDescriptor>
</riaData:FilterDescriptorCollection> </riaControls:DomainDataSource.FilterDescriptors></riaControls:DomainDataSource>
<!-- Filter: dates --><TextBlock Text="Date: " /><ComboBox x:Name="cmbDate" DropDownClosed="cmbDate_DropDownClosed"> <ComboBox.Items> <ComboBoxItem Content="All dates" IsSelected="True"/> <ComboBoxItem Content="Equal to"/> <ComboBoxItem Content="Since"/> <ComboBoxItem Content="Until"/> </ComboBox.Items></ComboBox><controls:DatePicker Name="dtpDate" />
I am trying to set the Operator for the filter1 FilterDescriptor on the DropDownClosed Event as follows:
int idx = cmbDate.SelectedIndex;
if (idx == 1) // Equal to option filter1.Operator = FilterOperator.IsEqualTo; if (idx == 2) // Since option filter1.Operator = FilterOperator.IsGreaterThanOrEqualTo;
if (idx == 3) // Until option filter1.Operator = FilterOperator.IsLessThanOrEqualTo;
The lines above are short versions, but I think they illustrate what I'm trying to do.
filter1 results NULL whatever I do. I've tried other approaches but with no success. Can anyone help me with this? I don't even know if this is the best way to do what I want. I'm open to suggestions.
Thanks in advance.
Ardman
Contributor
3344 points
926 Posts
11-07-2009 5:08 AM |
Have you tried to refresh your DomainDataSource after you've set the Filter Descriptor?
11-09-2009 6:12 AM |
Hello Ardman, can you explain better what you mean. I'm sorry but I'm pretty new to this Silverlight and RIA services world... :)
11-09-2009 6:18 AM |
Certainly, when you change the Filter operator, clear the data from the DomainDataSource and then call the Load method to refresh the data.
11-09-2009 6:55 AM |
Ok! :) I did it, but it results the same. I thought that when we referenced filter1 it would be recognized as the filter1 from the XAML file and all we had to do was changing its OPERATOR property, but it isn't recognized as being that object. When filter1.Operator line is executed returns 'Object reference not set to an instance of an object'...
11-09-2009 7:03 AM |
I'm not sure if this will work, but if you wanted to get the Filter from the DomainDataSource, you could try:
FilterDescriptor filterDesc = this.FindName("filter1") asFilterDescriptor;
filterDesc.Operator = FilterOperator.IsLessThanOrEqualTo;
But, I'm not sure this will work.
11-09-2009 7:36 AM |
It didn't work. :( Thanks anyway Ardman. :) I am still trying to discover how to do this. If you have any other ideas I'll be much appreciated. :) Cheers
If you remove the Filter Descpritor from the XAML and set it in the code only, does this work?
11-09-2009 9:16 AM |
Hi again! Problem solved! I created a FilterDescriptionCollection object which has all the filter descriptors in my DomainDataSource. All I did was to look inside that collection for a filter descriptor with the appropriate PropertyPath. This is the complete routine: FilterDescriptorCollection fdCol = ddsDataSource.FilterDescriptors; FilterDescriptor fdDate = null; foreach (FilterDescriptor fd in fdCol) { if (fd.PropertyPath == "Date") fdDate = fd; } int idx = cmbDate.SelectedIndex; if (idx == 1) // equal to fdDate.Operator = FilterOperator.IsEqualTo; if (idx == 2) // since fdDate.Operator = FilterOperator.IsGreaterThanOrEqualTo; if (idx == 3) // until fdDate.Operator = FilterOperator.IsLessThanOrEqualTo; this worked just fine. Thanks for your help anyway! :)