Solved

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

Posted on 2010-08-14
2
993 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
2 Comments
 
LVL 3

Accepted Solution

by:
bkokx earned 250 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 250 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now