accessing the cell’s control of the row and binding it with different datasource for every row in WPF datagrid

Jul 23, 2010 at 9:59 AM

I am using the WPF datagrid, I have added the columns DataGridComboBoxColumn, DataGridTemplateColumn   programatically,

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

 

                       DataGridComboBoxColumn colcombo = new DataGridComboBoxColumn();

           colcombo.Header = "FirstName";

            dataGrid1.Columns.Add(colcombo);

 

         ===================================================================

 

            DataGridTemplateColumn cbColcmbBox = new DataGridTemplateColumn();          

           cbColcmbBox.Header = "LastNamecombo";

           FrameworkElementFactory factorycombo = new                                                                        FrameworkElementFactory(typeof(ComboBox));

           DataTemplate cellTemplatecomb = new DataTemplate();

            cellTemplatecomb.VisualTree = factorycombo;

           cbColcmbBox.CellTemplate = cellTemplatecomb;          

           dataGrid1.Columns.Add(cbColcmbBox);

 

( is this the correct way to add the DataGridTemplateColumn if I want to access this programatically )