title: Hierarchical TreeView from DataSet
body: <p>I'm new in WPF and cant get how to bind that dataset to treeview</p>
  
  <pre><code>Dim dtHDD As New DataTable("Disks")
  dtHDD.Columns.Add("ID")
  dtHDD.Columns.Add("DiskName")
  
  dtHDD.Rows.Add(1, "Disc1")
  dtHDD.Rows.Add(2, "Disc2")
  
  Dim dtFolders As New DataTable("Folders")
  dtFolders.Columns.Add("ID")
  dtFolders.Columns.Add("DiskID")
  dtFolders.Columns.Add("FolderID")
  dtFolders.Columns.Add("FolderName")
  
  dtFolders.Rows.Add(1, 2, DBNull.Value, "Music")
  dtFolders.Rows.Add(2, 1, DBNull.Value, "Documents")
  dtFolders.Rows.Add(3, 1, 2, "Scatches")
  dtFolders.Rows.Add(4, 1, 3, "Images")
  dtFolders.Rows.Add(5, 1, 3, "Folder1")
  dtFolders.Rows.Add(6, 1, 2, "Bin")
  dtFolders.Rows.Add(7, 2, DBNull.Value, "Moves")
  dtFolders.Rows.Add(8, 1, 5, "Another one")
  
  
  Dim dtFiles As New DataTable("Files")
  dtFiles.Columns.Add("ID")
  dtFiles.Columns.Add("FolderID")
  dtFiles.Columns.Add("FileName")
  
  dtFiles.Rows.Add(1, 8, "file1")
  dtFiles.Rows.Add(2, 2, "file2")
  dtFiles.Rows.Add(3, 3, "file3")
  dtFiles.Rows.Add(4, 2, "file4")
  dtFiles.Rows.Add(5, 5, "file5")
  dtFiles.Rows.Add(6, 5, "file6")
  dtFiles.Rows.Add(7, 8, "file7")
  dtFiles.Rows.Add(8, 8, "file8")
  dtFiles.Rows.Add(9, 1, "file9")
  
  Dim ds As New DataSet
  ds.Tables.Add(dtHDD)
  ds.Tables.Add(dtFolders)
  ds.Tables.Add(dtFiles)
  ds.Relations.Add("DiskFolder", ds.Tables("Disks").Columns("ID"), ds.Tables("Folders").Columns("DiskID"))
  ds.Relations.Add("FolderFolder", ds.Tables("Folders").Columns("ID"), ds.Tables("Folders").Columns("FolderID"))
  ds.Relations.Add("FolderFile", ds.Tables("Folders").Columns("ID"), ds.Tables("Files").Columns("FolderID"))
  
  treeTest.ItemsSource = ds.Tables("Disks").DefaultView
  </code></pre>
  
  <p>So each disk can contain folders only.
  Each folder can contain files and folders.
  I made the following markup</p>
  
  <pre><code>&lt;TreeView x:Name="treeTest" Margin="380,0,0,0"&gt;
      &lt;TreeView.ItemTemplate&gt;
          &lt;HierarchicalDataTemplate ItemsSource="{Binding DiskFolder}"&gt;
              &lt;TextBlock Text="{Binding DiskName}"/&gt;
              &lt;HierarchicalDataTemplate.ItemTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;TextBlock Text="{Binding FolderName}" /&gt;
                  &lt;/DataTemplate&gt;
              &lt;/HierarchicalDataTemplate.ItemTemplate&gt;
          &lt;/HierarchicalDataTemplate&gt;
      &lt;/TreeView.ItemTemplate&gt;
  &lt;/TreeView&gt;
  </code></pre>
  
  <p>But I don't know how to set RowFilter rule for Folder table and how add files in that treeview.</p>