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

Synchonize data with the underlying binding item source problem

3 Answers 77 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Huy Truong The
Top achievements
Rank 1
Huy Truong The asked on 28 May 2009, 05:13 AM

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


3 Answers, 1 is accepted

Sort by
0
Tihomir Petkov
Telerik team
answered on 30 May 2009, 07:58 AM
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.
0
Rishabh Jain
Top achievements
Rank 1
answered on 27 Apr 2010, 01:57 PM
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
0
Miro Miroslavov
Telerik team
answered on 30 Apr 2010, 12:19 PM
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.
Tags
TreeView
Asked by
Huy Truong The
Top achievements
Rank 1
Answers by
Tihomir Petkov
Telerik team
Rishabh Jain
Top achievements
Rank 1
Miro Miroslavov
Telerik team
Share this question
or