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

How do you do a Parent/Child with a ViewModel

6 Answers 268 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Simplex
Top achievements
Rank 1
Simplex asked on 08 Jul 2009, 03:41 PM
We are using MVVM and want to keep all the binding and logic in the view model. All of your examples are with code behind. So, is there a way to define the parent and child in xaml and then do the binding in the view model?

Forgot to add that we also use a collection of Business Objects to bind to and not data sets.

The code below displays the child detail and it has all the objects columns list, but no data?

Thanks

Xaml Code:

            <telerik:RadGridView.Columns> 
                <telerik:GridViewDataColumn  
                        HeaderText="Policy Number"  
                        UniqueName ="PolicyNumber" 
                    > 
                    <telerik:GridViewColumn.CellTemplate> 
                        <DataTemplate> 
                            <TextBox  
                                HorizontalContentAlignment="Stretch"     
                                Text="{Binding Path=PolicyNumber, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"  
                                HorizontalAlignment="Left" VerticalAlignment="Top" /> 
                        </DataTemplate> 
                    </telerik:GridViewColumn.CellTemplate> 
                </telerik:GridViewDataColumn> 
                <telerik:GridViewDataColumn  
                        HeaderText="Insurance Name"  
                        UniqueName ="InsuranceName" 
                    > 
                    <telerik:GridViewColumn.CellTemplate> 
                        <DataTemplate> 
                            <TextBlock  
                                Text="{Binding Path=InsuranceName}"  
                                HorizontalAlignment="Left" VerticalAlignment="Top" /> 
                        </DataTemplate> 
                    </telerik:GridViewColumn.CellTemplate> 
                </telerik:GridViewDataColumn> 
            </telerik:RadGridView.Columns> 
            <telerik:GridViewDataControl.HierarchyChildTemplate> 
                <DataTemplate> 
                    <StackPanel> 
                        <telerik:RadGridView   
                            CanUserReorderColumns="False"  
                            CanUserFreezeColumns="False"   
                            ShowGroupPanel="False"  
                            ColumnsWidthMode="Auto"  
                            ItemsSource="{Binding Path=InsuranceProvider}" 
                        > 
                        </telerik:RadGridView> 
                    </StackPanel> 
                </DataTemplate> 
            </telerik:GridViewDataControl.HierarchyChildTemplate> 
        </telerik:RadGridView> 

Code Behind:
        Public Sub New() 
            InitializeComponent() 
 
            Dim InsProvDetailDefinition As New GridViewTableDefinition() 
            InsProvDetailDefinition.Relation = New PropertyRelation("InsuranceProvider") 
            Me.RadPatInsList.TableDefinition.ChildTableDefinitions.Add(InsProvDetailDefinition) 
 
 
        End Sub 

6 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 09 Jul 2009, 07:06 AM
Hi Edward,

I've made for you small example to illustrate you possible approach using single code behind line. For our first service pack (after two weeks) you will be able to define this directly in XAML:

<Window x:Class="WpfApplication1.Window1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" 
    xmlns:local="clr-namespace:WpfApplication1" 
    Title="Window1"
     <Grid> 
         <Grid.Resources> 
            <ObjectDataProvider x:Key="Customers" ObjectType="{x:Type local:DataClasses1DataContext}" MethodName="get_Customers" /> 
        </Grid.Resources> 
        <telerik:RadGridView Name="RadGridView1" ItemsSource="{Binding Source={StaticResource Customers}}"
            <telerik:GridViewDataControl.ChildTableDefinitions> 
                <telerik:GridViewTableDefinition /> 
            </telerik:GridViewDataControl.ChildTableDefinitions> 
            <telerik:GridViewDataControl.HierarchyChildTemplate> 
                <DataTemplate> 
                    <StackPanel> 
                        <telerik:RadGridView    
                            CanUserReorderColumns="False"   
                            CanUserFreezeColumns="False"    
                            ShowGroupPanel="False"   
                            ColumnsWidthMode="Auto"   
                            ItemsSource="{Binding Path=Orders}"
                        </telerik:RadGridView> 
                    </StackPanel> 
                </DataTemplate> 
            </telerik:GridViewDataControl.HierarchyChildTemplate> 
        </telerik:RadGridView> 
    </Grid> 
</Window> 
 


Please check the attachment and let me know how it goes.

All the best,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Simplex
Top achievements
Rank 1
answered on 09 Jul 2009, 06:50 PM
Thanks for the reply, but it still is not showing data. It shows the parent data and the correct columns for the child, but no data in the child.
PatientInsuranceItemViewModelList is a list of  PatientInsuranceItemViewModelList objects
InsuranceProvider is a property in the PatientInsuranceItemViewModelList object of type InsuranceProvider.

I tried adding :
            DirectCast(sender, RadGridView).DataContext = DirectCast(sender, RadGridView).ParentRow.DataContext
from a Loaded option in the grid view of the child. When I step through it, the correct data is being assigned to the DataContext, but it just give the spinning circles like it is trying to load.

Thanks


I
       <telerik:RadGridView  
            Name="RadPatInsList" HorizontalAlignment="Left"  
            Grid.Row="2" Grid.Column="0"  
            IsReadOnly="True" 
            MaxHeight="250"  
            ScrollViewer.CanContentScroll="True" 
            ScrollViewer.HorizontalScrollBarVisibility="Visible" 
            ScrollViewer.VerticalScrollBarVisibility="Visible" 
            telerik:StyleManager.Theme="Simple"  
            AutoGenerateColumns="False"   
            ColumnsWidthMode="Fill"  
            CanUserFreezeColumns="False" 
            ShowGroupPanel="False" 
            ItemsSource="{Binding Path=PatientInsuranceItemViewModelList }" 
        > 
            <telerik:RadGridView.Columns> 
                <telerik:GridViewDataColumn  
                        HeaderText="Policy Number"  
                        UniqueName ="PolicyNumber" 
                    > 
                    <telerik:GridViewColumn.CellTemplate> 
                        <DataTemplate> 
                            <TextBox  
                                HorizontalContentAlignment="Stretch"     
                                Text="{Binding Path=PolicyNumber, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"  
                                HorizontalAlignment="Left" VerticalAlignment="Top" /> 
                        </DataTemplate> 
                    </telerik:GridViewColumn.CellTemplate> 
                </telerik:GridViewDataColumn> 
                <telerik:GridViewDataColumn  
                        HeaderText="Insurance Name"  
                        UniqueName ="InsuranceName" 
                    > 
                    <telerik:GridViewColumn.CellTemplate> 
                        <DataTemplate> 
                            <TextBlock  
                                Text="{Binding Path=InsuranceName}"  
                                HorizontalAlignment="Left" VerticalAlignment="Top" /> 
                        </DataTemplate> 
                    </telerik:GridViewColumn.CellTemplate> 
                </telerik:GridViewDataColumn> 
            </telerik:RadGridView.Columns> 
            <telerik:GridViewDataControl.HierarchyChildTemplate> 
                <DataTemplate> 
                    <StackPanel> 
                        <telerik:RadGridView   
                            CanUserReorderColumns="False"  
                            CanUserFreezeColumns="False"   
                            ShowGroupPanel="False"  
                            ColumnsWidthMode="Auto"  
                            ItemsSource="{Binding Path=InsuranceProvider}" 
                        > 
                        </telerik:RadGridView> 
                    </StackPanel> 
                </DataTemplate> 
            </telerik:GridViewDataControl.HierarchyChildTemplate> 
        </telerik:RadGridView> 

0
Vlad
Telerik team
answered on 10 Jul 2009, 05:19 AM
Hi Edward,

If you can send us small running example I will gladly help you.

Kind regards,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Vlad
Telerik team
answered on 10 Jul 2009, 05:21 AM
Hi Edward,

If you can send us small running example I will gladly help you.

Kind regards,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Justin Manjooran
Top achievements
Rank 1
answered on 12 Nov 2009, 10:47 AM
Hi

I was also trying for the same and when I gave like

:
:

<

telerikGridView:RadGridView Margin="8" x:Name="EquipmentTypeGrid" UseAlternateRowStyle="True"

 

UseLayoutRounding="True" ColumnsWidthMode="Fill" AutoGenerateColumns="False"

 

ItemsSource="{Binding EquipmentList, Mode=TwoWay}"

 

vs:Services.Command="{Binding Path=SelectionCommand, Mode=TwoWay}">
<telerikGridView:RadGridView.ChildTableDefinitions>

 

 

 

 

 

<telerikGridView:GridViewTableDefinition/>

 

 

 

</telerikGridView:RadGridView.ChildTableDefinitions>

 

 

 

<telerikGridView:RadGridView.Columns>

 

 

 

<telerikGridView:GridViewDataColumn HeaderText="Equipment ID" IsReadOnly="True" DataMemberBinding="{Binding TypeId}" />

 

 

 

<telerikGridView:GridViewDataColumn HeaderText="Name" IsReadOnly="True" DataMemberBinding="{Binding Name}" />

 

 

 

<telerikGridView:GridViewDataColumn HeaderText="Hazmat." IsReadOnly="True" DataMemberBinding="{Binding HazMatCode}" />

 

 

 

</telerikGridView:RadGridView.Columns>

 

 

 

<telerikGridView:RadGridView.HierarchyChildTemplate>

 

 

 

<DataTemplate>

 

 

 

<StackPanel Background="#33629e">

 

 

 

<telerikGridView:RadGridView Margin="45,8,30,8" UseAlternateRowStyle="True" x:Name="EquipmentUnitGrid"

 

 

 

ItemsSource="{Binding EquipmentModelLists, Mode=TwoWay}" vs:Services.Command="{Binding Path=SelectionCommand, Mode=TwoWay}" ColumnsWidthMode="Fill"

 

 

 

AutoGenerateColumns="False">

 

 

 

<telerikGridView:RadGridView.Columns>

 

 

 

<telerikGridView:GridViewDataColumn HeaderText="Unit ID" DataMemberBinding="{Binding ID}" Width="180" />

 

 

 

<telerikGridView:GridViewDataColumn HeaderText="Serial No." IsReadOnly="True" DataMemberBinding="{Binding SerialNo}" Width="120" />

 

 

 

 

 

 

<telerikGridView:GridViewDataColumn HeaderText="Current Location" IsReadOnly="True" DataMemberBinding="{Binding EquipmentCurrentLocation}" Width="120" />

 

 

 

<telerikGridView:GridViewDataColumn HeaderText="Status" IsReadOnly="True" DataMemberBinding="{Binding EquipmentStatus}" Width="100" />

 

 

 

</telerikGridView:RadGridView.Columns>


i got data.
 
Now can you please help me on how to fire an event on the Innergrid double click ??
I'm using MVVM pattern.

Hi terlik team pls help me on this.. in which i'm using like

vs:Services.Command="{Binding Path=SelectionCommand, Mode=TwoWay}"> for binding with a command

but its not working for inner Grid.

 

pls send me response with akhi.cs@gmail.com also if possible

0
Milan
Telerik team
answered on 17 Nov 2009, 09:24 PM
Hi Justin Jose,

It is difficult to determine what the problem is without taking a look at the whole project and the command implementation. Could you please send us your project?


All the best,
Milan
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
Simplex
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Simplex
Top achievements
Rank 1
Justin Manjooran
Top achievements
Rank 1
Milan
Telerik team
Share this question
or