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

empty property causes update failure

2 Answers 77 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
David Ocasio asked on 15 Jul 2010, 09:57 PM
Not sure if this is a bug (probably not).
But i am posting it for posterity since it caused me grief.

If a collection property (observable collection) is nothing when first presented to the itemssource
any subsequent  assignments are not observed.

(My data class was generated by a webservice proxy and since it was just a shallow representation of the class the default new assignemnt for the collection was not reproduced in the client version.)

This can be worked around by making sure all the collections are initailized before assigning to the itemssource or
by reassinging the itemssource after the addition

My example below
click 1st button and a new item is added to a new initialized child collection but it is not displayed in the listview
click 2nd button and i reassign the who itemssource and it shows up.

<UserControl x:Class="RadControlsSilverlightApp8.MainPage"
    xmlns:telerikGridView="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView" 
    xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"
  
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
  <Grid x:Name="LayoutRoot">
        <StackPanel Orientation="Vertical">
            <Button Content="Add New Level " Height="23" HorizontalAlignment="Left"  Name="Button1" VerticalAlignment="Top"  />
            <Button Content="Reassign" Height="23" HorizontalAlignment="Left"  Name="Button2" VerticalAlignment="Top"  />
            <telerikGridView:RadTreeListView IsReadOnly="True" x:Name="tvKits" Grid.Row="1"  Grid.Column="1" AutoGenerateColumns="False" >
                <telerikGridView:RadTreeListView.ChildTableDefinitions>
                    <telerikGridView:TreeListViewTableDefinition ItemsSource="{Binding Items}" />                                       
                </telerikGridView:RadTreeListView.ChildTableDefinitions>
                <telerikGridView:RadTreeListView.Columns>
                    <telerikGridView:GridViewDataColumn Header="Assembly"  DataMemberBinding="{Binding Name}"  />
                </telerikGridView:RadTreeListView.Columns>
            </telerikGridView:RadTreeListView>
        </StackPanel>
    </Grid>
</UserControl>

Imports System.Collections.ObjectModel
  
Partial Public Class MainPage
    Inherits UserControl
  
    Dim zz As New ObservableCollection(Of Test)
    Public Sub New()
        InitializeComponent()
    End Sub
  
    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
        zz(0).Items(0).Items(0).Items = New ObservableCollection(Of Test)
        zz(0).Items(0).Items(0).Items.Add(New Test)
    End Sub
  
    Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button2.Click
        tvKits.ItemsSource = Nothing
        tvKits.ItemsSource = zz
    End Sub
  
    Private Sub tvKits_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles tvKits.Loaded
        zz.Add(New Test)
        zz(0).Items = New ObservableCollection(Of Test)
        zz(0).Items.Add(New Test)
  
        zz(0).Items(0).Items = New ObservableCollection(Of Test)
        zz(0).Items(0).Items.Add(New Test)
        tvKits.ItemsSource = zz
        '        tvKits.ExpandAllHierarchyItems()
    End Sub
End Class
  
Public Class Test
    Private _Items As ObservableCollection(Of Test)
    Public Property Items() As ObservableCollection(Of Test)
        Get
            Return _Items
        End Get
        Set(ByVal value As ObservableCollection(Of Test))
            _Items = value
        End Set
    End Property
    Private _Name As String = "AA"
    Public Property Name() As String
        Get
            Return _Name
        End Get
        Set(ByVal value As String)
            _Name = value
        End Set
    End Property
End Class

2 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 16 Jul 2010, 08:02 AM
Hello David Ocasio,

Please add the new items like this:

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
    'zz(0).Items(0).Items(0).Items = New ObservableCollection(Of Test)
    zz(0).Items(0).Items(0).Items.Add(New Test)
End Sub

Hope this helps.

Sincerely yours,
Veskoni
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 16 Jul 2010, 09:30 AM
that is the problem exactly

the backing store field _Items is defined as

Private _Items As ObservableCollection(Of Test)

and so must have the

zz(0).Items = New ObservableCollection(Of Test) 

or it will err out since _items is nothing

As i said the code for the class (test in this example) is not created by me persay but is generated by the web proxy .
it does not initilize the private member if there isn't any values

Again I dont consider this a bug, rather I post it as a clue if anyone has the control failing to update its children .
Check the initialization of the variables.

thanks
Veskoni
Tags
TreeListView
Asked by
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
Answers by
Veselin Vasilev
Telerik team
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
Share this question
or