This is the continuation to

> 
> [OnEvent datagrid column add fail](https://stackoverflow.com/questions/35293395/onevent-datagrid-column-add-fail)
> 
> 
> 

I have seen this post:

> 
> [How to add Data to a WPF datagrid programatically](https://stackoverflow.com/questions/11950312/how-to-add-data-to-a-wpf-datagrid-programatically)
> 
> 
> 

the datagrid is simply this:

```
<DataGrid Name="dtgResults" Background="Transparent" AutoGenerateColumns="False"/>

```

in which everything seems to work fine but when I put it in my solution it doesn't compile:

[![enter image description here](https://i.stack.imgur.com/1CrJw.png)](https://i.stack.imgur.com/1CrJw.png)

Can anyone explain me why?

---EDIT---

I realize now that I have misunderstood what's in the link above.
In short I have a datagrid binded to an observable collection. 
I have to add two more columns. How can that be done?

---EDIT2---- for CBreeze

```
 dtgResults.ItemsSource = obcmMyDim;<--------previous data here
 DataGridTextColumn textColumn1 = new DataGridTextColumn();
 textColumn1.Header = "AAA1";
 textColumn1.Binding = new Binding("AAA1");

 DataGridTextColumn textColumn2 = new DataGridTextColumn();
 textColumn2.Header = "AAA2";
 textColumn2.Binding = new Binding("AAA2");

 Application.Current.Dispatcher.BeginInvoke(new ThreadStart(() => dtgResults.Columns.Add(textColumn1)));
 Application.Current.Dispatcher.BeginInvoke(new ThreadStart(() => dtgResults.Columns.Add(textColumn2)));

 dtgResults.Items.Add(new { AAA1 = "Col1Row1", AAA2 = "Col2Row1"});
 dtgResults.Items.Add(new { AAA1 = "Col1Row2", AAA2 = "Col2Row2" });

```

---EDIT 3--- for JH
So in short I have that observable collection which binded to the datagrid make the following output:

[![enter image description here](https://i.stack.imgur.com/PUnq5.png)](https://i.stack.imgur.com/PUnq5.png)

then I add the columns with your method:

```
var names = obcmMyDim.First().obcItemsName; // All entries must have the same list of obcItemsName and in the same order
    for (int i = 0; i < names.Count; i++)
    {
      DataGridTextColumn c = new DataGridTextColumn();
      c.Header = names[i];

      var b = new Binding();
      string str = string.Format("obcmMyDim.obcItemsMeasured[{0}]", i);
      b.Path = new PropertyPath(str);
      b.Mode = BindingMode.TwoWay;

      c.Binding = b;

      dtgResults.Columns.Add(c);
    }

```

as for the binded array

[![enter image description here](https://i.stack.imgur.com/GVleZ.png)](https://i.stack.imgur.com/GVleZ.png)

[![enter image description here](https://i.stack.imgur.com/3x4Qk.png)](https://i.stack.imgur.com/3x4Qk.png)

and the bind str is "obcmMyDim.obcItemsMeasured[0]" ...1....n

but what I get is that the columns are there but they are empty

[![enter image description here](https://i.stack.imgur.com/Zp84c.png)](https://i.stack.imgur.com/Zp84c.png)