?
Solved

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

Posted on 2010-08-14
2
Medium Priority
?
1,032 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 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

807 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