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

Hierarchy and MVVM

10 Answers 532 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Roy Halvorsen
Top achievements
Rank 1
Roy Halvorsen asked on 20 Jan 2010, 10:00 AM
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.

10 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 20 Jan 2010, 11:57 AM
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.
0
Roy Halvorsen
Top achievements
Rank 1
answered on 20 Jan 2010, 12:37 PM
Thanks :-)
Exactly what I was looking for.
0
Roy Halvorsen
Top achievements
Rank 1
answered on 21 Jan 2010, 08:33 AM
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.

0
Vlad
Telerik team
answered on 21 Jan 2010, 09:05 AM
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.
0
Roy Halvorsen
Top achievements
Rank 1
answered on 21 Jan 2010, 09:32 AM
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; 
            } 
        } 
 



0
Vlad
Telerik team
answered on 21 Jan 2010, 09:43 AM
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.
0
Roy Halvorsen
Top achievements
Rank 1
answered on 21 Jan 2010, 09:58 AM
I'm not sure I understand what you mean about that. Can you give me an example?
0
Vlad
Telerik team
answered on 21 Jan 2010, 10:15 AM
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.
0
Roy Halvorsen
Top achievements
Rank 1
answered on 21 Jan 2010, 12:36 PM
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.
0
Accepted
Vlad
Telerik team
answered on 21 Jan 2010, 12:39 PM
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.
Tags
GridView
Asked by
Roy Halvorsen
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Roy Halvorsen
Top achievements
Rank 1
Share this question
or