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

Setting ObservableCollection as data source for RadTreeView for WinForms

3 Answers 243 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
asd
Top achievements
Rank 1
asd asked on 11 Jan 2016, 02:54 PM

Hi,

 I'm trying to migrate an app that was written in WPF using default tree view to Telerik UI WinForms RadTreeView. For the default tree that has been used previously I had an ObservableCollection to which I could add items and the change would be displayed in the TreeView immediately without me triggering any update method. However, with the Telerik's solution, when I set the DataSource to the observable collection, no change is visible even though that observable collection has been modified.

The final result that needs to be achieved is to be able to display folder structure on a disc. Now obviously, I don't want to load a folder and all of its subfolders at once, but rather only load the content when the user decides to open the given folder.

Can this be achieved using ObservableCollection and without the need of triggering some sort of update method?

Thanks

3 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 14 Jan 2016, 10:35 AM
Hi,

Thank you for writing.

Data binding in Windows Forms behaves differently compared to WPF. Please refer to the following MSDN resources:
I am sending you an example of a RadTreeView bound to a BindingList collection of models implementing the INotifyPropertyChanged interface. Another example is also available in our documentation: Load On Demand with CRUD operations.

I hope this helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo Merdjanov
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
srinivas
Top achievements
Rank 1
answered on 06 Oct 2020, 09:18 AM

HI Team 

Can you please share sample with multilevelTreeView with BindingList.

Person1

    Person1.1

    Person 1.2

      Person 1.2.1

      Person 1.2.2

Person 2

  Person 2.1

 

     

 

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 08 Oct 2020, 10:23 AM

Hello, Srinivas,

The provided tree view structure can be achieved by binding to self-referencing data. The following help article demonstrates a sample approach: https://docs.telerik.com/devtools/winforms/controls/treeview/data-binding/binding-to-self-referencing-data 

Even though the example shows a DataTable, it can be easily adopted to a BindingList of objects. Create a class, e.g. Item, where each item has similar properties as the columns in the DataTable. The important part here is to have a ParentID property and an ID one which to be used for specifying the ParentMember and ChildMember in RadTreeView. Thus, each Item will know its ID and who is its parent Item. 
 
I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).

Tags
Treeview
Asked by
asd
Top achievements
Rank 1
Answers by
Hristo
Telerik team
srinivas
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or