Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6834865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:09:49+00:00 2026-05-26T23:09:49+00:00

I have been looking for a some working code for the last couple of

  • 0

I have been looking for a some working code for the last couple of days to set up a treeview in my WPF app to display some database data. I use VB as i am much more confident in it – which drastically limited the code examples out there. More examples i found used manually entered data to populate each node versus a database which was little help.
I finally found some code which bound the each node to a query and related the query via a DataRelation. Great this should work perfect!

The example used the Northwind database so I changed it to my database and plugged in the queries. To my shock the treeview populated fine except…. all the data is invisible.

Here is the code:

Imports MySql.Data.MySqlClient
Imports System.Data
Imports System.ComponentModel
Imports System.Xml
Imports System.IO
Class Window2
Dim connStr As String = "Server=127.0.0.1;Database=psdb;Uid=root;Pwd=;Connect    Timeout=30;"
Dim conn As New MySqlConnection(connStr)
Function GetRelationalData() As DataSet

    Dim CategoryAdapter As MySqlDataAdapter = New MySqlDataAdapter("select distinct Dist_name, dist_id from distributors".ToString, conn)
    Dim ProductsAdapter  As MySqlDataAdapter = New MySqlDataAdapter("select d.dist_id, t.Title_name, title_id from titles t, distributors d where d.dist_id = t.dist_id".ToString, conn)
    Dim ProductData As DataSet = New DataSet()
    CategoryAdapter.Fill(ProductData, "Categories") 'fill Categories
    ProductsAdapter.Fill(ProductData, "Products") 'fill products
    Dim CategoryRelation As DataRelation
    CategoryRelation = New DataRelation("ChildrenRelationship", _
    ProductData.Tables("Categories").Columns("dist_id"), _
    ProductData.Tables("Products").Columns("dist_id"), True)
    CategoryRelation.Nested = True
    ProductData.Relations.Add(CategoryRelation)
    Return ProductData
End Function
Private Sub Button1_Click(ByVal sender As System.Object, _
                          ByVal e As RoutedEventArgs) Handles Button1.Click
    BindData()
End Sub
Private Sub BindData()
    TreeView1.DataContext = GetRelationalData()
End Sub

End Class

and the XAML:

<Window x:Class="Window2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="400" Width="550"><Window.Resources>
<DataTemplate x:Key="ProductTemplate" >
    <TextBlock Text="{Binding ProductName}"></TextBlock>
</DataTemplate>
<HierarchicalDataTemplate x:Key="CategoryTemplate" 
                  ItemsSource="{Binding ChildrenRelationship}" 
                  ItemTemplate="{StaticResource ProductTemplate}">
    <TextBlock Text="{Binding CategoryName}"></TextBlock>
</HierarchicalDataTemplate>
</Window.Resources>
<Grid>

and here what i end up with the data seems to be there but you can’t see it. Help!

enter image description here

PS there may be some confusion as to the objects. I went back tried to keep as close to the original code as possible when i discovered the problem only replacing the queries with my own – the original code used “Categories” and “Products” where as I “use Distributors” and “Titles”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:09:50+00:00Added an answer on May 26, 2026 at 11:09 pm

    OK Tim doesnt want the Kudos I guess. Here is the corrected code:

    <Window x:Class="Window2" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="Window1" Height="400" Width="550">
    <Window.Resources> 
    <DataTemplate x:Key="ProductTemplate" > 
    <TextBlock Text="{Binding title_name}">
    </TextBlock> 
    </DataTemplate> 
    <HierarchicalDataTemplate x:Key="CategoryTemplate"           
    ItemsSource="{Binding ChildrenRelationship}"                    
    ItemTemplate="{StaticResource   ProductTemplate}">     
    <TextBlock Text="{Binding dist_name}"></TextBlock> 
    </HierarchicalDataTemplate>
    </Window.Resources>
    <Grid> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been looking through some code on an open source project recently and
**Updated: (See below)**I have been looking around for couple of days and can't find
i have been looking around to find some nice working example of implementing Membership
I have been looking in to doing some test driven development for one of
I have been looking around on the web and found some articles about the
I have been looking for an answer for some time now, hope you could
I am looking for some input on something I have been thinking about for
I've been looking at some server logs using tail -f recently, and have thought
I'm needing some help with mod rewriting. I have been looking online for the
I have not done much database programming at all. I am working from some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.