473,785 Members | 2,255 Online
Bytes | Software Development & Data Engineering Community
+ 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 2400

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

Similar topics

3
2401
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 database? I think it is possible with PHP (version 5.0.2 is installed on the web server) to create a file with SQL commands which restore the data, but what is the easiest way to do it? Thanks in advance!
1
1426
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
1442
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 treeview based off a dataset that I've queried from our database. First, I'm manually creating and adding the "root" node to the treeview control. Then, I'm trying to iterate through my dataset and build all the folders and files under the root node.
6
3538
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
2432
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 App_Data folder In Windows Explorer, move to the root folder for the Web site. The default location for your new Web site is c:\inetpub\wwwroot\AccessSample.
2
3834
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. What I would like to do is create a treeview from this table. For example: Table:
0
985
by: karthickmca6 | last post by:
how to convert database data to spread sheets 7.0,
1
5613
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 when binding the TreeView to a data source control using the DataSourceID property or when the TreeNodePopulate event is handled." Here is the code within my page load handler: if (!IsPostBack) {
2
1293
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 relevant row. Any ideas how I approach this?
2
1111
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 connect & acess the data of that table in my web-form. My databse is in sql server & form is in asp.net
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9481
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10341
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10155
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10095
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8979
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2881
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.