Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

WPF ListView data binding with embedded ComboBox

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 05-30-2007   #1 (permalink)
Krish_xx
Guest


 

WPF ListView data binding with embedded ComboBox

How can I set the SelectedItem in a ComboBox which is populated by collection
of custom objects, and also embedded in to a ListView .

This is the code sample that I ma using but it is not functioning.

this.Resources.Add("typeObjCollection", this.GetTypes());

<Page.Resources>
<CollectionViewSource Source="{StaticResource typeObjCollection}"
x:Key="cvs"/>
</Page.Resources>

<Grid>
<ListView Name="list">
<ListView.View>
<GridView>
<GridViewColumn Header="Type">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding Source={StaticResource
cvs}}" DisplayMemberPath="TypeName" IsSynchronizedWithCurrentItem="False"
SelectedItem="{Binding Path=myType, Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}"></ComboBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>

Highly appreciate your early response to this.


My System SpecsSystem Spec
Old 06-01-2007   #2 (permalink)
Laurent Bugnion, MVP
Guest


 

Re: WPF ListView data binding with embedded ComboBox

Hi,

Krish_xx wrote:
> How can I set the SelectedItem in a ComboBox which is populated by collection
> of custom objects, and also embedded in to a ListView .
>
> This is the code sample that I ma using but it is not functioning.
>
> this.Resources.Add("typeObjCollection", this.GetTypes());
>
> <Page.Resources>
> <CollectionViewSource Source="{StaticResource typeObjCollection}"
> x:Key="cvs"/>
> </Page.Resources>
>
> <Grid>
> <ListView Name="list">
> <ListView.View>
> <GridView>
> <GridViewColumn Header="Type">
> <GridViewColumn.CellTemplate>
> <DataTemplate>
> <ComboBox ItemsSource="{Binding Source={StaticResource
> cvs}}" DisplayMemberPath="TypeName" IsSynchronizedWithCurrentItem="False"
> SelectedItem="{Binding Path=myType, Mode=TwoWay,
> UpdateSourceTrigger=PropertyChanged}"></ComboBox>
> </DataTemplate>
> </GridViewColumn.CellTemplate>
> </GridViewColumn>
> </GridView>
> </ListView.View>
> </ListView>
>
> Highly appreciate your early response to this.


I think that the DataContext is not clear, since you didn't set the
"Source" property nor the "ElementName" on the binding.

The DataContext, if not set explicitly, is inherited through the logical
tree (the parent, or the parent's parent, etc...). Where is the "myType"
property defined? If it's on the Window, then you can set an x:Name on
the Window tag, and then use that name as ElementName on the binding.

HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Binding Problem in ComboBox Horst Klein Avalon 0 09-13-2007 02:50 AM
WPF binding error when databinding a ComboBox inside a ListView it jeff.townes Avalon 0 05-01-2007 11:05 AM
ComboBox Binding to DataClass Horst Klein Avalon 1 03-01-2007 09:46 AM
Two-way binding doesn't work with ComboBox.Text? Keith Patrick Avalon 0 11-02-2006 06:20 PM
Binding a ComboBox to in internal property Keith Patrick Avalon 4 10-04-2006 08:40 AM


Update your Vista Drivers Update Your Vista Drivers Now!!

Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008
Page generated in 0.25527 seconds with 10 queries