views:

772

answers:

2

I have a DataGrid bound to a DataTable that I want to make custom columns for using a DataGridTemplateColumn, but I'm not sure how to reference the value in the cells of the DataTable. Every example I see online either binds the DataTable and doesn't change the templates, or uses a custom object and references the properties of the bound object. Does anyone know how to reference the values stored in the DataTable from within a control in the DataGridTemplateColumn?

Thanks, Brian

Edit: I see now that I can use the name of the column in the data table as the binding path. Unfortunately, I was going to try and assign the templates to the columns dynamically, so I won't know the current column's name. Is there another way to do what I am looking to do (Assign a template to each column or cell in a DataGrid programmatically)?

A: 

I'm having the same problem and I have to say the documentation that Microsoft provides for the WPF DataGrid is TOTALLY RUBBISH. I've scoured the internet looking for an example of how to do this and found NONE so clearly the control is inadequate.

The only thing that seems to work on the WPF Datagrid are primitive types.

I tried to do something basic as create a DataTable of my custom type (e.g Person) with some properties. I have tried every trick I've read of to use a DataGridTemplateColumn programmatically when binding the DataTable to the WPF DataGrid and all the examples are giving politician's answers (thus avoiding the real question).

One solution declares the DataTemplate in the XAML at designtime which is useless since the DataTable is dynamic (so not the answer).

The closest I've come was by creating an ObservableCollection and binding that to the DataGrid (Again not the real answer).

Other than that. Nothing binds regardless of how many things I've changed or tried. So I end up with blank controls, which is pretty annonying.

Chris J
A: 

The question was asked an answered on a stackoverflow question I posed here.

link text

Chris J