0

Im making a herbal database program and I am having troubles setting up HierarchicalDataTemplates for my main data class.

Tree layout wanted:

  • Glossary
    • Category1
      • Letter (Reduces overall list size)
        • Entry
          • Note1
          • Note2
  • Herbs

    • Botanical Name

      • Alphabetical
        • Letter (Reduces overall list size)
          • Entry
      • By Family
        • Family
          • Entry
    • Common Name

      • Letter (Reduces overall list size)
        • Entry

NOTE: All entries have notes NOTE2: Letter is a letter of the alphabet for sorting

Ex:

  • a
    • apple
  • b
    • bus

Main Class:

Public Class MainSystem
    Public herbs As New Dictionary(Of Integer, herbEntry)
    Public glossary As New Dictionary(Of Integer, glossaryEntry)
End Class

GlossaryEntry:

Public Class glossaryEntry
    Public Property ID As Integer
    Public Property Words As List(Of String) 'Each word is in the format: Catagory/word
    Public Property Notes As SortedDictionary(Of String, String)
End Class

HerbEntry:

Public Class herbEntry
    Public ID As Integer
    Public Property commonName As List(Of String)
    Public Property botanicalName As List(Of String)
    Public Property PlantID As PlantID
End Class

EDIT: Thanks to the link from @AngelWPF I have got the tree displaying my object. But, currently the tree looks like this:

  • Herbs
    • Common Name
      • CommonName item from entry
      • Another CommonName item from entry
    • Common Name
      • CommonName item from entry
      • Another CommonName item from entry

How can I make this change to match my hierarchy?

XAML:

<UserControl.Resources>
        <HierarchicalDataTemplate  DataType="{x:Type my:herbEntry}">
            <TreeViewItem Header="Common Name"  ItemsSource="{Binding commonName}">

            </TreeViewItem>
        </HierarchicalDataTemplate>
    </UserControl.Resources>
    <Grid>
        <TreeView HorizontalAlignment="Stretch" Name="TreeView1" VerticalAlignment="Stretch">
            <TreeViewItem Header="Herbs" ItemsSource="{Binding herbs.Values}"/>
        </TreeView>
    </Grid>
ags131
  • 23
  • 5
  • I still dont have a complete solution, the link @AngelWPF posted helped alot in getting me started, but i still havent found a way to organize the tree. So far, the only method i can think of is to generate custom node objects in the hierarchy that I need and display that. But thats sounds a little too hacky to me. In some ways, WinForms is MUCH easier... – ags131 Oct 08 '11 at 05:52

1 Answers1

0

This example may guide you to assign different item templates at different levels for each type of bound item ...

Having HierarchicalDataTemplates in a TreeView

Community
  • 1
  • 1
WPF-it
  • 19,625
  • 8
  • 55
  • 71
  • Thanks! That was very helpful. Now I'm having problems getting the catagories and sorting. Updated post with my partial solution – ags131 Oct 03 '11 at 17:28