473,473 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

WPF TreeView binding to Database data

3 New Member
Hi All,

I'm quite new to programming and I am trying to bind some data stored in Sybase DB to a treeView in WPF. My data consists of information about PartyGroups and for each PartyGroup there are Persons associated with that group. So far I have managed to bind the data so that it displays a list of PartyGroups in the treeView but cannot get my head around hierarchical data templates i.e how to link the Persons. Would appreciate any help, many thanks!

Ben

Expand|Select|Wrap|Line Numbers
  1. //Entity Class
  2.     public class PartyGroup
  3.     {
  4.         public int PersonID { get; set; }
  5.         public string FullName { get; set; }
  6.         public int PartyID { get; set; }
  7.         public string PartyName { get; set; }
  8.  
  9.         public List<PartyGroup> PartyGroupList { get; set; }
  10.  
  11.     }
  12.  
  13. //Database
  14.         private List<PartyGroup> myPartyGroupList;
  15.  
  16.         public IEnumerable<PartyGroup> PartyGroupList
  17.         {
  18.             get { return myPartyGroupList; }
  19.         }
  20.             using (AseDataReader reader = command.ExecuteReader())
  21.             {
  22.                 while (reader.Read())
  23.                 {
  24.                     PartyGroup partyGroup = new PartyGroup();
  25.                     partyGroup.PersonID = Convert.ToInt32(reader["person_id"]);
  26.                     partyGroup.FullName = reader["full_name"].ToString();
  27.  
  28.                     partyGroup.PartyID = Convert.ToInt32(reader["party_group_id"]);
  29.                     partyGroup.PartyName = reader["party_group_name"].ToString();
  30.  
  31.  
  32.                     myPartyGroupList.Add(partyGroup);
  33.  
  34.                 }
  35.             }
  36. //XAML
  37. <TreeView x:Name="treeview" Margin="131,129,203,29" ItemsSource="{Binding PartyGroupList, Mode=Default}">
  38.             <TreeView.Resources>
  39.                 <HierarchicalDataTemplate   DataType="{x:Type local:PartyGroup}"
  40.                                             ItemsSource="{Binding PartyGroupList}">
  41.                     <StackPanel>
  42.                         <TextBlock Text="{Binding PartyName, Mode=Default}"/>
  43.  
  44.                     </StackPanel>
  45.  
  46.                 </HierarchicalDataTemplate>
  47.  
  48.                 <!--<HierarchicalDataTemplate DataType="{x:Type PartyGroupList}">??         
  49.                     <StackPanel>
  50.                         <TextBlock Text="{Binding FullName, Mode=Default}"/>
  51.                     </StackPanel>
  52.                 </HierarchicalDataTemplate>-->
  53.  
  54.             </TreeView.Resources>
  55.  
  56.         </TreeView>
Dec 15 '10 #1
0 2381

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Colin Finck | last post by:
Hello! I need to backup a MySQL database (MySQL 4.0). But it is on a shared-hosting web server and so I don't have direct server access. I also have no phpMyAdmin installed. How can I backup the...
1
by: Hrvoje Voda | last post by:
I would like a simple code witch fills treeview control with data from sqlDataBase through sqlAdapter and DataSet. Hrcko
0
by: Teemu | last post by:
Hello. Please bear with me if this seems like a basic question (I'm just getting started with all this ASP.NET and WebControls stuff). Anyway, I'm trying to programmatically build a...
6
by: QT | last post by:
Dear Sirs, I have a database table which has 4 column such as Document Name Subpart Title I want to make a treeview like this
9
by: dennist685 | last post by:
Walkthrough: Creating a Web Page to Display Access Database Data I've started the above walkthrough. However, near the beginning it gives the following instructions To set permissions in the...
2
by: thanneman | last post by:
Hello all, First off all, I appollogize for my englisch. I have a problem. I have a table in my sql database with 2 fields. Field 1 is an ID, and Field 2 contains the complete file locations. ...
0
by: karthickmca6 | last post by:
how to convert database data to spread sheets 7.0,
1
by: aaronh64 | last post by:
I'm trying to bind to the ASP.NET TreeView control and utilize the PopulateOnDemand functionality. However, I am receiving the following (very confusing) error: "PopulateOnDemand only supported...
2
by: anonymoushamster | last post by:
Dropdown A is column from database Dropdown B is column from database Data in A and B must be from same row. If user click an item from A, then B is updated to display its data from...
2
by: ims | last post by:
I am trying to bind an existing database that contains table using the dataset table adapter. I want to access the data from the table as well as can edit the data from the asp.form.How can i...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.