S
S
SitrixEug2016-02-10 12:11:50
WPF
SitrixEug, 2016-02-10 12:11:50

How to display a flat list as a tree in DataGrid or TreeView(WPF, C#)?

There is a table. It contains records of the form
ID, Name, FK
where FK points to another record in the same table.
I am using Entity Framework. The table is loaded into an ObservableCollection, for a working binding.
I can’t figure out yet how to display it as a tree in a DataGrid or in a TreeView, and in order to save the binding (do not leave the ObservableCollection that I get from the DataContext).
Maybe someone did, tell me where to dig, or maybe give an example?
Thanks

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav Makarov, 2016-02-10
@Nipheris

<TreeView ItemsSource="{Binding СвойствоОбщейВьюМоделиСодержащееКоллекциюЗаписей}">
    <TreeView.ItemTemplate>
        <HierarchicalDataTemplate ItemsSource="{Binding СвойствоОбъектаСсылающеесяНаОбъектРодитель}" DataType="{x:Type local:КлассОбъекта}">
            <TreeViewItem Header="{Binding СвойствоВОбъектеСТекстомДляОтображенияВУзле}"/>
        </HierarchicalDataTemplate>
    </TreeView.ItemTemplate>
</TreeView>

Don't forget to add a description for the local namespace.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question