![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
| |
| | #1 (permalink) |
| | 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) |
| | 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 | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| binding to combobox itemssource? | .NET General | |||