Click here to Skip to main content
12,950,099 members (42,849 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
We are new to WPF and we can Bind the combobox inside a datagrid but we are unable to populate the inserted value in the combobox while retrieving.

Can any body help us? Thanks in Advance.
Posted 18-Jul-12 1:12am
Comments
Sandeep Mewara 18-Jul-12 14:22pm
   
New, yet would have made some effort, right? Share with us.
dinesh.ms.net 19-Jul-12 4:04am
   
Hey Sandeep,
Thanks for your suggetion. I have tried and it is working fine in a sample application but we are implementing the same concept in MVVM using prism we are unable to bind the data that is what I am trying for.
you can find my sample code below,
.cs
Locations = new List<mylocation> { new MyLocation { Location = "London", NAMEID = 1 }, new MyLocation { Location = "Amsterdam", NAMEID = 2 } };
Persons = new List<Person> { new Person { NAME = "Jack", NAMEID = 1 }, new Person { NAME = "Jill", NAMEID = 2 } };
DataContext = this;

Xaml,
<DataGrid AutoGenerateColumns="False" Name="dgMain" ItemsSource="{Binding Locations}" CanUserAddRows="False">
<datagrid.columns>
<DataGridTextColumn Binding="{Binding Location}"/>
<datagridtemplatecolumn>
<datagridtemplatecolumn.celltemplate>
<datatemplate>
<ComboBox ItemsSource="{Binding Persons, RelativeSource={RelativeSource AncestorType=Window}}" DisplayMemberPath="NAME" SelectedValuePath="NAMEID" SelectedValue="{Binding NAMEID}" />




dinesh.ms.net 19-Jul-12 4:05am
   
Xaml code is,
<DataGrid AutoGenerateColumns="False" Name="dgMain" ItemsSource="{Binding Locations}" CanUserAddRows="False">
<datagrid.columns>
<DataGridTextColumn Binding="{Binding Location}"/>
<datagridtemplatecolumn>
<datagridtemplatecolumn.celltemplate>
<datatemplate>
<ComboBox ItemsSource="{Binding Persons, RelativeSource={RelativeSource AncestorType=Window}}" DisplayMemberPath="NAME" SelectedValuePath="NAMEID" SelectedValue="{Binding NAMEID}" />




This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 5,749
CHill60 3,380
Maciej Los 2,953
Jochen Arndt 1,935
ppolymorphe 1,820


Advertise | Privacy | Mobile
Web01 | 2.8.170525.1 | Last Updated 18 Jul 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100