Create a virtual level in treeview

1 Answer 52 Views
TreeView
Deltaohm
Top achievements
Rank 3
Bronze
Iron
Iron
Deltaohm asked on 26 Apr 2023, 10:07 AM

Hi

I have a model class that it is in the form

Class A
{
	public List<B> B {get;set;}
	public List<C> C {get;set;}
}

And I would build a treeview with a list of A: A1, A2 in this way:


A1
	Objects of type B
		B1
		B2
	Objects of type C
		C1
		C2
A2
	Objects of type B
		B3
		B4
	Objects of type C
		C3
		C4

But the second level is missing in the model class (we can see it as a "virtual level"). Is there a way to add the level directly in xaml (the number and the tags of the elements are fixed by design).

Thank you

Luigi

1 Answer, 1 is accepted

Sort by
0
Accepted
Petar Mladenov
Telerik team
answered on 01 May 2023, 05:22 AM

Hi Luigi,

The best way to handle such scenarios is to introduce additional ViewModels and build hierarchy of such viewmodels to replicate what you need to display as hirarchy in the UI. Ofr example if your models are A which is parent of Bs and Cs, you can create ViewModelA which is parent of ViewModelBBase and ViewModelCBase, then ViewModelBBAse is parent of ViewModelB and etc. This way the hierarchy ViewModelA-ViewModelBBAse-ViewModelB is eaasy to bind in the UI with chain of HierarchicalDataTemplates/HierarchicalDataTemplateSelectors.

Regards,
Petar Mladenov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
TreeView
Asked by
Deltaohm
Top achievements
Rank 3
Bronze
Iron
Iron
Answers by
Petar Mladenov
Telerik team
Share this question
or