This is a migrated thread and some comments may be shown as answers.

RadGridView Filter Settings

7 Answers 304 Views
GridView
This is a migrated thread and some comments may be shown as answers.
John Thompson
Top achievements
Rank 2
John Thompson asked on 05 Oct 2010, 09:30 PM
In the 0924 release of the Silverlight 4 controls I get the following in my serialization of the filter settings:

System.Runtime.Serialization.InvalidDataContractException: Type 'Telerik.Windows.Data.FilterDescriptor+FilterDescriptorUnsetValue' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. Alternatively, you can ensure that the type is public and has a parameterless constructor - all public members of the type will then be serialized, and no attributes will be required.

The setting are created from your example code and then serialized for saving in the database.  The serialization code looks like this:

List<Type> types = new List<Type>();
 
types.Add(typeof(List<Telerik.Windows.Controls.GridView.Settings.ColumnSetting>));
types.Add(typeof(List<Telerik.Windows.Controls.GridView.Settings.FilterSetting>));
types.Add(typeof(List<Telerik.Windows.Controls.GridView.Settings.GroupSetting>));
types.Add(typeof(List<Telerik.Windows.Controls.GridView.Settings.SortSetting>));
types.Add(typeof(List<Telerik.Windows.Controls.GridView.Settings.PropertySetting>));
 
DataContractSerializer serializer = new DataContractSerializer(settings.Settings.GetType(), types);
 
MemoryStream ms = new MemoryStream();
 
serializer.WriteObject(ms, settings.Settings);

What do I need to change to restore functionality for my users?

7 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 06 Oct 2010, 09:44 AM
Hello John Thompson,

You have to modify your code a little bit.

In the place where the filters are serialized add the following check. If the a FilterDescriptor.Value == FilterDescriptor.UnsetValue then do not serialize this filter and continue. For example:

if (!(cfd.FieldFilter.Filter1.Value == FilterDescriptor.UnsetValue))
{
    setting.Filter1 = new Telerik.Windows.Data.FilterDescriptor();
    setting.Filter1.Member = cfd.FieldFilter.Filter1.Member;
    setting.Filter1.Operator = cfd.FieldFilter.Filter1.Operator;
    setting.Filter1.Value = cfd.FieldFilter.Filter1.Value;
    setting.Filter1.MemberType = null;
}
 
if (!(cfd.FieldFilter.Filter2.Value == FilterDescriptor.UnsetValue))
{
    setting.Filter2 = new Telerik.Windows.Data.FilterDescriptor();
    setting.Filter2.Member = cfd.FieldFilter.Filter2.Member;
    setting.Filter2.Operator = cfd.FieldFilter.Filter2.Operator;
    setting.Filter2.Value = cfd.FieldFilter.Filter2.Value;
    setting.Filter2.MemberType = null;
}
 
foreach (Telerik.Windows.Data.FilterDescriptor fd in cfd.DistinctFilter.FilterDescriptors.OfType<Telerik.Windows.Data.FilterDescriptor>())
{
    if (fd.Value == FilterDescriptor.UnsetValue)
    {
        continue;
    }
    Telerik.Windows.Data.FilterDescriptor newFd = new Telerik.Windows.Data.FilterDescriptor();
    newFd.Member = fd.Member;
    newFd.Operator = fd.Operator;
    newFd.Value = fd.Value;
    newFd.MemberType = null;
    setting.SelectedDistinctValues.Add(newFd);
}

Conversely, add a check for null on the way back when you deserialize. For example:

if (setting.Filter1 != null)
{
    cfd.FieldFilter.Filter1.Member = setting.Filter1.Member;
    cfd.FieldFilter.Filter1.Operator = setting.Filter1.Operator;
    cfd.FieldFilter.Filter1.Value = setting.Filter1.Value;
}
 
if (setting.Filter2 != null)
{
    cfd.FieldFilter.Filter2.Member = setting.Filter2.Member;
    cfd.FieldFilter.Filter2.Operator = setting.Filter2.Operator;
    cfd.FieldFilter.Filter2.Value = setting.Filter2.Value;
}
 
foreach (Telerik.Windows.Data.FilterDescriptor descriptor in setting.SelectedDistinctValues)
{
    cfd.DistinctFilter.FilterDescriptors.Add(descriptor);
}

You get the idea -- if there is a filter with this UnsetValue as its Value -- simply ignore it altogether.

I hope this helps.

Sincerely yours,
Ross
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
John Thompson
Top achievements
Rank 2
answered on 06 Oct 2010, 11:51 AM
Your hopes are realized.  It worked great!  I also added a check as follows to allow the user to load pre-0924 filters.

if (setting.Filter1 != null)
{
    cfd.FieldFilter.Filter1.Member = setting.Filter1.Member;
    cfd.FieldFilter.Filter1.Operator = setting.Filter1.Operator;
 
    if (setting.Filter1.Value != null)
    {
        cfd.FieldFilter.Filter1.Value = setting.Filter1.Value;
    }
    else
    {
        cfd.FieldFilter.Filter1.Value = Telerik.Windows.Data.FilterDescriptor.UnsetValue;
    }
}
 
if (setting.Filter2 != null)
{
    cfd.FieldFilter.Filter2.Member = setting.Filter2.Member;
    cfd.FieldFilter.Filter2.Operator = setting.Filter2.Operator;
 
    if (setting.Filter2.Value != null)
    {
        cfd.FieldFilter.Filter2.Value = setting.Filter2.Value;
    }
    else
    {
        cfd.FieldFilter.Filter2.Value = Telerik.Windows.Data.FilterDescriptor.UnsetValue;
    }
}

It seems to be working like a charm!  Thank you so much for your help.
0
Prince
Top achievements
Rank 1
answered on 13 Feb 2012, 12:23 PM
Im working on radgridview to save settings to the database and return wen user select saved settings, In the forum  i can find where you do that, any help
0
Dimitrina
Telerik team
answered on 15 Feb 2012, 02:18 PM
Hello,

 You could check this forum thread for more information on that topic.

All the best,
Didie
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Mask
Top achievements
Rank 1
answered on 15 Feb 2012, 02:30 PM
0
Rossen Hristov
Telerik team
answered on 15 Feb 2012, 02:37 PM
Hello,

In what way is your question related with the topic that we discuss in this thread?

Please, don't spam a Save/Load Filter Settings topic with something that is totally unrelated.

You can open a new forum thread if you want to (it is free), not just post your question if the very first forum thread that you see even though it has absolutely nothing to do with it.

Does this make any sense?

Greetings,
Ross
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Mask
Top achievements
Rank 1
answered on 15 Feb 2012, 02:39 PM
Could you answer it?
Tags
GridView
Asked by
John Thompson
Top achievements
Rank 2
Answers by
Rossen Hristov
Telerik team
John Thompson
Top achievements
Rank 2
Prince
Top achievements
Rank 1
Dimitrina
Telerik team
Mask
Top achievements
Rank 1
Share this question
or