Click here to Skip to main content
16,015,072 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: Best Way To Do This Pin
Pete O'Hanlon4-May-11 13:17
mvePete O'Hanlon4-May-11 13:17 
GeneralRe: Best Way To Do This Pin
Kevin Marois4-May-11 13:21
professionalKevin Marois4-May-11 13:21 
GeneralRe: Best Way To Do This Pin
SledgeHammer014-May-11 14:19
SledgeHammer014-May-11 14:19 
AnswerRe: Best Way To Do This Pin
Renat Khabibulin4-May-11 16:55
Renat Khabibulin4-May-11 16:55 
AnswerRe: Best Way To Do This Pin
RichardGrimmer20-May-11 3:58
RichardGrimmer20-May-11 3:58 
QuestionWCF RIA / MVVM Question Pin
eddieangel4-May-11 11:33
eddieangel4-May-11 11:33 
AnswerRe: WCF RIA / MVVM Question Pin
Pete O'Hanlon4-May-11 12:25
mvePete O'Hanlon4-May-11 12:25 
QuestionHow do I databind a ListView to a property in child collection in WPF? Pin
B2C4-May-11 3:01
B2C4-May-11 3:01 
Let's say I have a State class that has a collection of Counties:

public class State
{
	public State()
	{
		Counties = new ObservableCollection<County>();
	}

	public String StateName
	{ get; set; }

	public String NickName
	{ get; set; }

	public ObservableCollection<County> Counties
	{ get; set; }
}

public class County
{
	public County()
	{
	}

	public String CountyName
	{ get; set; }

	public String Population
	{ get; set; }
}


Now, let's say I have a View that has a ListView (I have used MVVM architecture, so the View is a UserControl).

The View has the DataContext set to a collection of States (this is actually done via a DataTemplate).

How do I use databinding to display a single row for each county? The sticking point for me is that I want to display the Name of the State on the same row as the CountyName and Population.

For instance, the ListView might have the following records:

State Name | County Name | Population
Alabama | Acounty | 20000
Alabama | Bcounty | 40000
Colorado | CntyNm | 10000

The code in the UserControl might look something like this...which doesn't work...
<ListView ItemsSource="{Binding}"> 
        <ListView.View>
             <GridView>
                    <GridViewColumn Header=" State Name " DisplayMemberBinding="{Binding StateName}" />
                    <GridViewColumn Header=" County Name" DisplayMemberBinding="{Binding Counties.CountyName}" />
                    <GridViewColumn Header=" Population " DisplayMemberBinding="{Binding Counties.Population}"/>
             </GridView>
        </ListView.View>
</ListView>


I have been able to bind to properties of the State, properties of the County, but not both. I want a single record, or row, in the ListView for each County in each State. I want to show the name of the State too. I'm really asking for this specifically. I'm not looking to use grouping since this doesn't work with what my client's needs. I've created this example with the hopes that States/Counties are easier to understand and would use grouping if this were the data I was actually working with.
AnswerRe: How do I databind a ListView to a property in child collection in WPF? Pin
RichardGrimmer4-May-11 4:33
RichardGrimmer4-May-11 4:33 
GeneralRe: How do I databind a ListView to a property in child collection in WPF? Pin
B2C4-May-11 5:15
B2C4-May-11 5:15 
GeneralRe: How do I databind a ListView to a property in child collection in WPF? Pin
SledgeHammer014-May-11 7:00
SledgeHammer014-May-11 7:00 
GeneralRe: How do I databind a ListView to a property in child collection in WPF? Pin
AspDotNetDev4-May-11 7:59
protectorAspDotNetDev4-May-11 7:59 
AnswerRe: How do I databind a ListView to a property in child collection in WPF? Pin
Ian Shlasko4-May-11 5:40
Ian Shlasko4-May-11 5:40 
QuestionPrintable Area's Size - SL Printing API Pin
jadughar4-May-11 0:38
jadughar4-May-11 0:38 
AnswerRe: PageVisual's Size - SL Printing API Pin
Pete O'Hanlon4-May-11 2:18
mvePete O'Hanlon4-May-11 2:18 
GeneralRe: PageVisual's Size - SL Printing API Pin
jadughar4-May-11 4:24
jadughar4-May-11 4:24 
QuestionMVVM Pin
arkiboys3-May-11 22:50
arkiboys3-May-11 22:50 
AnswerRe: MVVM Pin
Dave Kerr3-May-11 23:09
mentorDave Kerr3-May-11 23:09 
GeneralRe: MVVM Pin
arkiboys3-May-11 23:19
arkiboys3-May-11 23:19 
QuestionSilverlight Compatibility with existing C#2.0 libraries Pin
insanechingi3-May-11 22:14
insanechingi3-May-11 22:14 
AnswerRe: Silverlight Compatibility with existing C#2.0 libraries Pin
Pete O'Hanlon3-May-11 23:14
mvePete O'Hanlon3-May-11 23:14 
QuestionSilverlight best Printing solution ??? Pin
jadughar2-May-11 4:08
jadughar2-May-11 4:08 
AnswerRe: Silverlight best Printing solution ??? Pin
Pete O'Hanlon2-May-11 9:40
mvePete O'Hanlon2-May-11 9:40 
AnswerRe: Silverlight best Printing solution ??? Pin
Mycroft Holmes2-May-11 13:10
professionalMycroft Holmes2-May-11 13:10 
GeneralRe: Silverlight best Printing solution ??? Pin
jadughar3-May-11 23:36
jadughar3-May-11 23:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.