Click here to Skip to main content
15,890,416 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
I am having a combo box in data grid in WPF. I am unable to bind data. I have used the below code.

XML
<DataGrid Name="grdDetails" Width="578" Height="149" ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollBarVisibility="Visible" AutoGenerateColumns="False"  MouseRightButtonUp="grdDetails_MouseRightButtonUp" SelectionChanged="grdDetails_SelectionChanged">
<DataGrid.Columns>
<DataGridTemplateColumn Width="80" Header="Country">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
                                    <TextBlock Text="{Binding Country}" ></TextBlock>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                            <DataGridTemplateColumn.CellEditingTemplate>
                                <DataTemplate>
                                    <ComboBox Name="cbCountry" ItemsSource="{Binding Path=CountryList}" SelectedItem="Code" DisplayMemberPath="Code" SelectedValuePath="Code"></ComboBox>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellEditingTemplate>
                        </DataGridTemplateColumn>
                    </DataGrid.Columns>
                </DataGrid>


Code Behind (C#)

List CountryList = new List(); CountryList = refController.GetCountryData(); // this brings the list of Country.

Please advice.
Posted
Comments
Prasad Khandekar 27-May-14 10:41am    
Please checkout this (http://weblogs.asp.net/manishdalal/archive/2008/09/28/combobox-in-datagrid.aspx) article.

 
Share this answer
 
you need to set the ItemsSource for the datagrid like this
C#
grdDetails.ItemsSource  = CountryList;
 
Share this answer
 

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