Synchonize data with the underlying binding item source problem

4 posts, 0 answers
  1. Huy Truong The
    Huy Truong The avatar
    32 posts
    Member since:
    Mar 2008

    Posted 28 May 2009 Link to this post

    Dear,


    According the instuction of using RadTreeView (refer to Operation not supported on read-only collection) , in case using the ItemSource of TreeView, we must modify the underling collection to add/ remove items of controls.


    But that does not work ( the treeView does not synchonize data with the underlying binding item source).


    Please get these example with ORANGAZIATION type has ORG_ID and ORG_NAME properties:

     

    SilverLight1.xaml:  have a RadTreeView and a Button to remove each item of underlying source on each click

    <telerikNavigation:RadTreeView   Grid.Row="0" Grid.Column="0" x:Name="radtvAssignJob"   >

                            <telerikNavigation:RadTreeView.ItemTemplate>

                                <DataTemplate>

                                    <StackPanel Orientation="Horizontal" >

                                        <TextBlock   VerticalAlignment="Center" Text="{Binding JAB_NAME}" Width="Auto" TextWrapping="Wrap"></TextBlock>

                                    </StackPanel>

                                </DataTemplate>

                            </telerikNavigation:RadTreeView.ItemTemplate>

    </telerikNavigation:RadTreeView>

     

    SilverLight1.xaml.cs

    List<ASSIGNJOBSWCFService.JOBABILITIES> lst = new List<CMS.UC.ASSIGNJOBSWCFService.JOBABILITIES>();    

     

            public SilverlightControl1()

            {

                InitializeComponent();

            }

            private void UserControl_Loaded(object sender, RoutedEventArgs e)

            {

                ASSIGNJOBSWCFService.JOBABILITIES itm ;

                for ( int i = 0 ; i < 10 ; i ++)

                {

                    itm = new CMS.UC.ASSIGNJOBSWCFService.JOBABILITIES();

                    itm.JAB_NAME = "JAB_NAME" + i;

                    lst.Add(itm);

                }

                radtvAssignJob.ItemsSource = lst;

            }

     

            private void btnCut_Click(object sender, RoutedEventArgs e)

            {

                lst.RemoveAt(0);

            }

     

    It does not work with purpose of synchonize data with the underlying binding item source whenever node is removed by clicking


    Could you help to solve this problem? Thank you for your help

    Best regards,

    Huy


  2. Tihomir Petkov
    Admin
    Tihomir Petkov avatar
    576 posts

    Posted 30 May 2009 Link to this post

    Hi Huy,

    There is no need to substitue the entire source collection if you want changes to that collection to be reflected in the treeview that is bound to it. All you have to do is use a collection that implements the INotifyPropertyChanged interface which basically throws an event notifying anyone interested that there has been a change in the collection. Please take a look at the attached sample application that I prepared for you. It demonstrates how to bind a treeview to the proper king of collection which allows changes to the source collection to be reflected in the treeview. Let me know if you have other questions.

    Greetings,
    Tihomir Petkov
    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.
  3. Rishabh Jain
    Rishabh Jain avatar
    1 posts
    Member since:
    Apr 2010

    Posted 27 Apr 2010 Link to this post

    Hi,

    I am not using INotifyPropertyChanged interface but i am having same issue as mentioned above. I need to update RadTreeView's data without INotifyPropertyChanged interface. so Is there any other way to do it ?  

    Here is my  RadTreeView:     
        
          <telerikNavigation:RadTreeView x:Name="treParentContacts" VerticalAlignment="Top" HorizontalAlignment="Left"
                                           ItemTemplate="{StaticResource templateParentContactEntry}"                                       
                                           Margin="10" IsLineEnabled="True" IsDragDropEnabled="True"                                      
                                           ExpanderStyle="{StaticResource ExpanderStyle1}"
                                           UseLayoutRounding="True"                                      
                                           ItemsOptionListType ="CheckList"
                                           IsOptionElementsEnabled="False"
                                           SelectionMode="Single"
                                           Width="930"
                                           IsEditable="False"                                         
                                           > 
            </telerikNavigation:RadTreeView>

    I am able to add data on it by the following  line:-
         treParentContacts.ItemsSource = root.Parents;

    But when i am going to update root.parents and call above line its not going to modify on silverlight page.

    Anybody please help, How can I do it ?

    Thanks
    Rishabh
  4. Miro Miroslavov
    Admin
    Miro Miroslavov avatar
    588 posts

    Posted 30 Apr 2010 Link to this post

    Hello Rishabh Jain,

    The only way to make DataBinding works is using INotifyPropertyChanged, or your object has to be DependencyObject and the property - DependencyProperty. So we recommend you to re-design your code and implement the INotifyPropertyChanged.

    About re-setting the ItemsSource property you have to set it a new instance of the Collection (root.Parents) in order to have the RadTreeView updated (like other Silverlight ItemsControls). 
    You'll need to write something like this, but it's code that you shouldn't use. It's very bad practice to re-create the whole tree every time you change something small, as well.

    treParentContacts.ItemsSource = new ObservableCollection<yourType>(root.Parents);

    Sincerely yours,
    Miro Miroslavov
    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.
Back to Top