?
Solved

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

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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

762 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