How to add datagridcomboboxcolumn in WPF C# DataGrid runtime

Mar 19 2016 3:40 AM
How a use Add DataGridComboBoxColumn in wpf DataGrid at Runtime.
User Specify total number of columns at runtime. According to runtime input the colunm should be created dynamically. Here i'm not able to add new row.
 
  1. <DataGrid x:name="dataGrid"/>  
  1. DataGridTextColumn so = new DataGridTextColumn();  
  2. so.Header = "S.No";  
  3. dataGrid.Columns.Add(so);  
  4.    
  5. DataGridTextColumn name= new DataGridTextColumn();  
  6. name.Header = " Name";  
  7. dataGrid.Columns.Add(name);  
  8.    
  9. DataGridColumn age= new DataGridTextColumn();  
  10. age.Header = "Age";  
  11. dataGrid.Columns.Add(age);  
  12.    
  13. for (int i = 1; i <= (new Random()).Next(1, 50); i++)  
  14. {  
  15.     DataGridComboBoxColumn ss = new DataGridComboBoxColumn();  
  16.     ss.Header = i;  
  17.     List<string> list = new List<string>();  
  18.     list.Add("Item 1");  
  19.     list.Add("Item 2");  
  20.     ss.ItemsSource = list;  
  21.     ss.Width = 50;  
  22.     ss.EditingElementStyle = style;  
  23.    
  24.     dataGrid.Columns.Add(ss);  
  25. }