I'm trying to add some columns to a data grid that is defined in the RowDetailsTemplate of an outer grid.
I see there is a method on the dataGrid.RowDetailsTemplate.LoadContent that will return the nested dataGrid. I can get ahold of the nested grid and programmatically, .NET allows me to add new columns however, when displayed, the new columns don't show.
When this loop is completed, I can see the new columns added to the datagrid..... what steps do I need to take to update the datagrid defn in the RowDetailsTemplate?
Here is a snippet:
//get the datagrid from the RowDetailsTemplate which is the nested Grid
Microsoft.Windows.Controls.DataGrid dataGridOrders = dataGridCutomers.RowDetailsTemplate.LoadContent() as DataGrid;
if (dataGridOrders != null)
#region dynamically create the columns that need to bind to child attribute
//use the first element as a template to create the columns
//the Assumption is that there will always be the same number of columns for any grid
//or nested grid (though the parent grid and child grid may not need the same #)
for (int count = 0; count < Model.Orders.OrderDetails.Count; count++)
DataGridTextColumn newColumnX = new DataGridTextColumn();
//The header can come from somewhere else...this is for example purposes
newColumnX.Header = "OrderDetails.Quantity " + count.ToString();
Binding bindingX = new Binding("OrderDetails[" + count.ToString() + "].Quantity");
bindingX.Mode = System.Windows.Data.BindingMode.TwoWay;
newColumnX.Binding = bindingX;