Answer the question
In order to leave comments, you need to log in
How to display table from DB in TreeView WPF?
There is a hierarchical table shown in the figure.
There is a connection to the database.
How to display this table in TreeView?
-Guitar
-----Acoustic
------------Classical
------------ 6-string(metal strings)
-----Bass
--- -------- Acoustic
------------ 4-string
----- Keyboard
------------ Synth
------- ----- midi keyboard
Answer the question
In order to leave comments, you need to log in
You need to create a class like this:
class Item
{
public string Name {get;set;}
public IEnumerable<Item> Children
{
get {/* тут код получения из базы подчинённых элементов*/}
}
}
<TreeView>
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Children}">
<TextBlock Text="{Binding Name}" />
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question