![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| 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 Specs![]() |
| | #2 (permalink) |
| 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 Specs![]() |
![]() |
| 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 |