Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

WPF Binding to a sub collection of custom objects in a class

Posted on 2010-08-14
2
Medium Priority
?
1,026 Views
Last Modified: 2013-11-12
Hi All

Im pretty impressed with the abilities of WPF, it looks far more capable than Windows Forms, however I am still finding my feet with its data binding abilities.

I have a custom object, a Project, each project is made up serveral other objects like contactor costs and milestones and delivery information. Each type of contractor will have serveral Milestones and there will be costs associated with each Milestone.

I would like to display a collection of Projects in a list box but in each ItemTemplate I would like to show a listbox showing the Milestone costs of the Building Contractor. Each Milestone is the same type of object but is made up of a Milestone property (walls complete) a date property (date when the walls are expected to be put up) and a Cost property (the wall costs x)

I would programatically access a milestone object as:

For each p as Project in Projects
For each M as Milestone in p
Listbox1.Items.Add(m.Milestone & "-" & m.Date)
Next
Next

Any ideas on how I can bind this to a listbox?

Happy to share more code if needs be

Thx

Chris
0
Comment
Question by:ChrisAllison
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Accepted Solution

by:
bkokx earned 1000 total points
ID: 33439507
Hi ChirsAllison,

Sorry to be blunt, but why a listbox to display all projects and milestones?
A ListView would be much better since then you could use a tree view
Personally I would even use a combo or listbox to select a project and use a secondary listbox to display the milestones for the selected project.

There are many good examples to do the databinding, have a look at:
http://msdn.microsoft.com/en-us/magazine/cc163299.aspx
http://coredotnet.blogspot.com/2006/05/wpf-data-binding-tutorial.html
http://www.c-sharpcorner.com/uploadfile/raj1979/databinding10042007165025pm/databinding.aspx
http://www.codeproject.com/KB/linq/linqtutorial3.aspx
0
 
LVL 5

Assisted Solution

by:berXpert
berXpert earned 1000 total points
ID: 33448736
Hello,

You can try a master- detail approach.

A list in the right can show the projects, a list in the left will display a list of milestones for the selected project.

Take a look to Bea Stollnitz sample:
http://bea.stollnitz.com/blog/?p=14
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question