Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using the WPF datagrid, I have added the columns DataGridComboBoxColumn, DataGridTemplateColumn programatically.

I want every row (every comboBox) of the the column with the different datasource may be first row’s ComboBox will have 5 items and second row’s ComboBox will have 3 items.

------------added blank StackPanel ---------------
XML
<UserControl.Resources>
        <DataTemplate x:Key="manageAreaCellTemplate">
            <StackPanel Orientation="Horizontal">
            </StackPanel>
        </DataTemplate>
</UserControl.Resources>


C#
//--------------Added Column ------------
DataGridTemplateColumn dgTemplateColumn = new DataGridTemplateColumn();
dgTemplateColumn.Width = new DataGridLength(1, DataGridLengthUnitType.Star);
dgTemplateColumn.Header = "Manage Options";
dgTemplateColumn.CellTemplate = this.FindResource("manageAreaCellTemplate") as DataTemplate;
dataGrid1.Columns.Add(dgTemplateColumn);
//-------------- dataGrid1_LoadingRow  Event------------

void dataGrid1_LoadingRow(object sender, Microsoft.Windows.Controls.DataGridRowEventArgs e)
{
            DataTemplate dt = (DataTemplate)e.Row.FindResource("manageAreaCellTemplate");
            object stk = dt.LoadContent();
            StackPanel stk1 = new StackPanel();
            stk1 = (StackPanel)stk;
            ComboBox cmb = new ComboBox();
            PortInfoCollection portInfoCollection = new PortInfoCollection();
            cmb.ItemsSource = portInfoCollection;
            cmb.SelectedValuePath = "Visits";
            cmb.DisplayMemberPath = "Port";
            stk1.Children.Add(cmb);
}

My problem is combobox is not getting populated in the grid.
Posted
Updated 27-Jul-10 0:35am
v2

1 solution

Go like this way:

First fill datatable or dataset.

u can access the combobox of the grid like below

ComboBox cb=(ComboBox)e.row.FindControl("YourCombo")


cb.DataSource=dt or ds

cb.databind()


Cheers
 
Share this answer
 
Comments
farookbe2006 27-Jul-10 7:09am    
Reason for my vote of 1
I am using WPF datagrid.. where this logic will not work
farookbe2006 27-Jul-10 7:10am    
I am using WPF datagrid.. where this logic will not work

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