Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - WPF ListView data binding with embedded ComboBox

 
 
Old 05-30-2007   #1 (permalink)
Krish_xx


 
 

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


 
 

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
 

Thread Tools


Similar Threads
Thread Forum
binding to combobox itemssource? .NET General


Vista Forums 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 Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46