HierarchyChildTemplate Example in VB

6 posts, 0 answers
  1. Joel
    Joel avatar
    21 posts
    Member since:
    Feb 2011

    Posted 05 Oct 2011 Link to this post

    I have been tring to get my grid to use HierarchyChildTemplate so I can display child data.  From all of the examples I've seen I have the XAML set up correctly however I do believe I don't have the Data setup right.

    This is my main data source:
    Imports System
    Imports System.ComponentModel
    Imports System.Collections.ObjectModel
     
    Public Class sosInvoice
        Implements INotifyPropertyChanged
     
     
        Private _GrossAmount As String
        Public Property GrossAmount() As String
            Get
                Return _GrossAmount
            End Get
            Set(ByVal value As String)
     
                If _GrossAmount <> value Then
                    _GrossAmount = value
                    NotifyPropertyChanged("GrossAmount")
                End If
     
            End Set
        End Property
     
        Public Distribution As List(Of sosDistribution)
     
        Private Sub NotifyPropertyChanged(ByVal PropertyName As String)
            Dim eNew As New PropertyChangedEventArgs(PropertyName)
            RaiseEvent PropertyChanged(Me, eNew)
        End Sub
     
        Public Event PropertyChanged(sender As Object, e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
    End Class

    This is the Distribution class:
    Imports System
    Imports System.ComponentModel
    Imports System.Collections.ObjectModel
     
    Public Class sosDistribution
        Implements INotifyPropertyChanged
     
     
        Private _Amount As String
        Public Property Amount() As String
            Get
                Return _Amount
            End Get
            Set(ByVal value As String)
                If _Amount <> value Then
                    _Amount = value
                    NotifyPropertyChanged("Amount")
                End If
            End Set
        End Property
     
        Public Event PropertyChanged(sender As Object, e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
     
        Private Sub NotifyPropertyChanged(ByVal PropertyName As String)
            Dim eNew As New PropertyChangedEventArgs(PropertyName)
            RaiseEvent PropertyChanged(Me, eNew)
        End Sub
     
     
    End Class

    Does this look right?

    I use the following XAML:
    <telerik:RadGridView Name="rgdInvoices"
                         Canvas.Left="12" Canvas.Top="63"
                         Height="478" Width="834"
                         telerik:StyleManager.Theme="Windows7"
                         ItemsSource="{StaticResource sosInvoice}"
                         IsFilteringAllowed="False"
                         CanUserSortColumns="False"
                         CanUserResizeColumns="False"
                         CanUserReorderColumns="False"
                         CanUserFreezeColumns="False"
                         FrozenColumnCount="3"
                         CanUserDeleteRows="False"
                         CanUserInsertRows="False"
                         ShowGroupPanel="False"
                         ShowInsertRow="False"
                         RowIndicatorVisibility="Collapsed"
                         AutoGenerateColumns="False"
                         RowLoaded="rgdInvoices_RowLoaded"
                         >
         
        <telerik:RadGridView.Columns>
             
        <telerik:GridViewDataColumn Header="Gross Amount" DataMemberBinding="{Binding GrossAmount, Mode=TwoWay}" >
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding GrossAmount}" />
                </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
            <telerik:GridViewDataColumn.CellEditTemplate>
                <DataTemplate>
                        <TextBox Text="{Binding GrossAmount, Mode=TwoWay}" />
                    </DataTemplate>
            </telerik:GridViewDataColumn.CellEditTemplate>
        </telerik:GridViewDataColumn>
         
        </telerik:RadGridView.Columns>
     
         
     <telerik:RadGridView.HierarchyChildTemplate>
        <DataTemplate>
                <telerik:RadGridView
                                    BorderThickness="0,1,0,1"
                                    telerik:StyleManager.Theme="Windows7"
                                    IsFilteringAllowed="False"
                                    CanUserSortColumns="False"
                                    CanUserResizeColumns="False"
                                    CanUserReorderColumns="False"
                                    CanUserFreezeColumns="False"
                                    CanUserDeleteRows="False"
                                    CanUserInsertRows="False"
                                    ShowGroupPanel="False"
                                    ShowInsertRow="False"
                                    RowIndicatorVisibility="Collapsed"
                                    ItemsSource="{Binding Distribution}"
                                    AutoGenerateColumns="False"
                                        >
                    <telerik:RadGridView.Columns>
     
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding Amount}"   Header="Amount" />
                    </telerik:RadGridView.Columns>
                </telerik:RadGridView>
            </DataTemplate>
        </telerik:RadGridView.HierarchyChildTemplate>
     
        <telerik:RadGridView.ChildTableDefinitions>
            <telerik:GridViewTableDefinition>
                <telerik:GridViewTableDefinition.Relation>
                    <telerik:PropertyRelation ParentPropertyName="Distribution"/>
                </telerik:GridViewTableDefinition.Relation>
            </telerik:GridViewTableDefinition>
        </telerik:RadGridView.ChildTableDefinitions>
     
    </telerik:RadGridView>

    here's how I load these classes with data:
    Public Shared g_Invoices As New sosInvoiceList
    ...
     
      'Load data into the collections so it loads with data from here
            For l_iIndex As Integer = 1 To 20
                Dim l_newInvoice As New sosInvoice
                l_newInvoice.ID = l_iIndex
                l_newInvoice.GrossAmount = (l_iIndex * 20).ToString
                l_newInvoice.Distribution = New List(Of sosDistribution)
     
                For l_iIndex2 = 1 To 10
                    Dim l_newDist As New sosDistribution
     
                    l_newDist.Amount = "99"
     
                    l_newInvoice.Distribution.Add(l_newDist)
                Next
     
                g_Invoices.Add(l_newInvoice)
            Next
     
            rgdInvoices.ItemsSource = g_Invoices

    I can get the Invoices to show yet no Distributions in the child records, only the header appears.
    again, I would like a complete example in VB if possible.
    Thanks.
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 06 Oct 2011 Link to this post

    Hello,

     According to your code you do not have public Distribution property in sosInvoice class. 

    Best wishes,
    Vlad
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. Joel
    Joel avatar
    21 posts
    Member since:
    Feb 2011

    Posted 06 Oct 2011 Link to this post

    I thought the following code did that:

    Public Distribution As List(Of sosDistribution)

    If not how would l write that.  I feel this is where I am having the issue.
    Thanks.

  4. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 06 Oct 2011 Link to this post

    Hi,

     This is declaration of field  - not a property. 

    Regards,
    Vlad
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  5. Joel
    Joel avatar
    21 posts
    Member since:
    Feb 2011

    Posted 06 Oct 2011 Link to this post

    Can you provide a VB example of how to write that?

    Thanks.
  6. Joel
    Joel avatar
    21 posts
    Member since:
    Feb 2011

    Posted 06 Oct 2011 Link to this post

    I finally got it.  This is how I wrote it.  I finally found a VB example in the online documentation.
    Private _Distribution As List(Of sosDistribution)
        Public Property Distribution() As List(Of sosDistribution)
            Get
                Return _Distribution
            End Get
            Set(ByVal value As List(Of sosDistribution))
                _Distribution = value
            End Set
        End Property

    Thanks.
Back to Top