Change Query to Query+QueryParameters and back

3 posts, 1 answers
  1. Nikita
    Nikita avatar
    2 posts
    Member since:
    Jul 2010

    Posted 26 Jan 2011 Link to this post

    There is the RadDDS and the RadGridView in the xaml:
        DomainContext="{Binding Path=context}"
        AutoLoad="True" />
        ItemsSource="{Binding ElementName=RadSource, Path=DataView}"

    I need to change the query to query+parameters in my code-behind. I do it this way:
    using swd = System.Windows.Data;
    using twc = Telerik.Windows.Controls;
    RadSource.AutoLoad = false;
    RadSource.DomainContext = null;
    RadSource.QueryName = "GetPersonSetByDepartmentId";
    RadSource.QueryParameters.Add(/*here create new parameter*/);
                   new swd.Binding(){ Path = new swd.PropertyPath("context") } );
    RadSource.AutoLoad = true;
    That's work.

    But when I try to change it back:
    1 RadSource.AutoLoad = false;
    2 RadSource.DomainContext = null;
    3 RadSource.QueryName = "GetPersonSetQuery";
    4 RadSource.QueryParameters.Clear();
    5 RadSource.SetBinding(/*...*/);
    6 RadSource.AutoLoad = true;
    7 RadSource.Load();
    I have got an error in the 4th line:
    "System.NullReferenceException in Telerik.Windows.Controls.RadDomainDataSource.PrepareParameterValue(ParameterInfo serverParameter)".
    I have tried to swap the 3rd and 4th lines. It has been useless.

    Attempt to reinitialize property QueryParameters
    RadSource.SetValue(RadDomainDataSource.QueryParametersProperty,new QueryParameterCollection());
    no results, cause "Cannot change read-only DependencyProperty".

    How can I clear or reset this property or change Query+Parameters to Query?
  2. Answer
    Nedyalko Nikolov
    Nedyalko Nikolov avatar
    871 posts

    Posted 01 Feb 2011 Link to this post

    Hi Nikita,

    Sorry for the late answer.
    RadDomainDataSource control uses special logic to handle all changes in every critical parameter like DomainContext, QueryName, QueryParameters and etc. However we have a solution for this problem, actually the solution is part of the xaml nature of this control (we cannot assume that any parameter or property will be set when we handle another property change). Your example perfectly illustrates this - when you set QueryName we perform a check that method with same name exists on the server, but we also check if QueryParameters are correct (by type and by name). Same check is performed when QueryParameters are changed. And what happens when you set QueryName there is no correct QueryParameters and vice versa. Now the solution - RadDomianDataSource implements ISupportInitialize interface which will help with such problems - just call radDomainDataSource.BeginInit() before and radDomainDataSource.EndInit() after initialization of the control.

    this.rdds.AutoLoad = false;
    this.rdds.QueryName = "GetCustomers";
    this.rdds.AutoLoad = true;

    Let me know if there is something unclear or if this doesn't help.

    All the best,
    Nedyalko Nikolov
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  3. Nikita
    Nikita avatar
    2 posts
    Member since:
    Jul 2010

    Posted 01 Feb 2011 Link to this post

    Hi Nadyalko,
    it's works. Thanks a lot!
Back to Top