Hierarchy and MVVM

11 posts, 1 answers
  1. Roy Halvorsen
    Roy Halvorsen avatar
    83 posts
    Member since:
    Oct 2008

    Posted 20 Jan 2010 Link to this post

    I have a GridView that works fine, but now I have to expand the GridView to have a Details grid inside which have another datacontract then its parent GridView. The relation between the two datacontracts is an ID. I am using MVVM. I can not find anything about this in the documentation, so some examples or help would be much appreciated.
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 20 Jan 2010 Link to this post

    Hello,

    You can create additional property to return details data filtered by ID. You can check this post which is very similar to your case:
    http://blogs.telerik.com/vladimirenchev/posts/09-10-16/how_to_silverlight_grid_hierarchy_load_on_demand_using_mvvm_and_ria_services.aspx

    Sincerely yours,
    Vlad
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Roy Halvorsen
    Roy Halvorsen avatar
    83 posts
    Member since:
    Oct 2008

    Posted 20 Jan 2010 Link to this post

    Thanks :-)
    Exactly what I was looking for.
  5. Roy Halvorsen
    Roy Halvorsen avatar
    83 posts
    Member since:
    Oct 2008

    Posted 21 Jan 2010 Link to this post

    I was too quick...
    How is this done when using properties in the ViewModel? I have tried the example in the blog, but it doesn't work for me. The child grid never loads any data. When expanding a row, shouldn't there be a proprty in the RadGrid telling the ViewModel that something has changed, and let me be able to get some id or index from the row that's been expanded? I tried RowLoaded, but that property is used when using codebehind and not MVVM.

  6. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 21 Jan 2010 Link to this post

    Hello Roy,

    If the child collection in INotifyCollectionChanged (for example ObservableCollection<T>) the grid will display the data automatically.

    Kind regards,
    Vlad
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. Roy Halvorsen
    Roy Halvorsen avatar
    83 posts
    Member since:
    Oct 2008

    Posted 21 Jan 2010 Link to this post

    Im not sure I get your answer correctly. Here is my RadGrid:
    <telerik:RadGridView Name="rgvPatientNew" 
        ItemsSource="{Binding Model}" 
        RowIndicatorVisibility="Collapsed" 
        CanUserFreezeColumns="False" 
        IsFilteringAllowed="False" 
        AutoGenerateColumns="False" 
        ShowGroupPanel="False" 
        IsReadOnly="True" 
        SelectedItem="{Binding CurrentPatientNew, Mode=TwoWay}"
        <telerik:RadGridView.ChildTableDefinitions> 
            <telerik:GridViewTableDefinition  /> 
        </telerik:RadGridView.ChildTableDefinitions> 
        <telerik:RadGridView.Columns> 
            <telerik:GridViewDataColumn Header="#" Width="70" DataMemberBinding="{Binding PasId}" IsVisible="True" /> 
            <telerik:GridViewDataColumn Header="FNr" Width="100" DataMemberBinding="{Binding OfficialId}" DataType="{x:Type System:String}" /> 
            <telerik:GridViewDataColumn Header="Navn" Width="200" DataMemberBinding="{Binding Name}" DataType="{x:Type System:String}" /> 
        </telerik:RadGridView.Columns> 
        <telerik:RadGridView.HierarchyChildTemplate> 
            <DataTemplate> 
                <telerik:RadGridView IsReadOnly="True"  
                AutoGenerateColumns="False"  
                ItemsSource="{Binding ChildModel}" 
                RowIndicatorVisibility="Collapsed" 
                CanUserFreezeColumns="False" 
                IsFilteringAllowed="False" 
                ShowGroupPanel="False"
                <telerik:RadGridView.Columns> 
                    <telerik:GridViewDataColumn Header="#" Width="60" DataMemberBinding="{Binding PasId}" IsVisible="True" /> 
                    <telerik:GridViewDataColumn Header="Id" Width="60" DataMemberBinding="{Binding WaitinglistId}" IsVisible="True" /> 
                </telerik:RadGridView.Columns> 
                </telerik:RadGridView> 
            </DataTemplate> 
        </telerik:RadGridView.HierarchyChildTemplate> 
    </telerik:RadGridView> 

    And here is a part ov the ViewModel:
            private ObservableCollection<ModelDataContract> _Model; 
            public ObservableCollection<ModelDataContract> Model 
            { 
                get { return _Model ?? (_Model = new ObservableCollection<ModelDataContract>()); } 
            } 
     
            public ObservableCollection<ChildModelDataContract> ChildModel 
            { 
                get 
                { 
                    if (!childModelLoaded) 
                    { 
                        int PasId = 10019848; //This should be tha ID from the Expanded Row 
     
                        foreach (var myValye in UnityContainer.Resolve<IModelServiceAgent>().GetChildModels(PasId.ToString())) 
                        { 
                            ChildModel.Add(myValye); 
                        } 
     
                        childModelLoaded = true
                    } 
     
                    return ChildModel; 
                } 
            } 
     



  8. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 21 Jan 2010 Link to this post

    Hi Roy,

    ChildModel property should be on ModelDataContract class.

    Best wishes,
    Vlad
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  9. Roy Halvorsen
    Roy Halvorsen avatar
    83 posts
    Member since:
    Oct 2008

    Posted 21 Jan 2010 Link to this post

    I'm not sure I understand what you mean about that. Can you give me an example?
  10. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 21 Jan 2010 Link to this post

    Hi,

    You can find an example application attached.

    Greetings,
    Vlad
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  11. Roy Halvorsen
    Roy Halvorsen avatar
    83 posts
    Member since:
    Oct 2008

    Posted 21 Jan 2010 Link to this post

    Thanks for your example, Vlad, but it doesn't help me much. All the DataContracts is within the Data Layer of the application, so I am not able to create the ChildModel property where you suggest.
  12. Answer
    Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 21 Jan 2010 Link to this post

    Hello Roy,

    DataContracts is partial class you can extend it similar to what I've done in the blog post with RIA services.

    All the best,
    Vlad
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top
UI for WPF is Visual Studio 2017 Ready