Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Comments
Sandeep Mewara 18-Jul-12 14:22pm    
New, yet would have made some effort, right? Share with us.
Rajesh Buddaraju 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}">




Rajesh Buddaraju 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900