views:

301

answers:

1

I am creating a DataForm from dynamic data (so I can't create the columns in the xaml), I currently create columns for my DataGrid (I have not worked out how I can create a button + event in a colomn yet)

foreach (var item in headings.Entities)
                    {
                        theDataGrid.Columns.Add(
                            new DataGridTextColumn
                            {
                                Header = item.Label,
                                Binding = new Binding(item.LocalName)
                            });
                    }

I cannot see any methods to add fields to a DataForm at runtime, however...

A: 

You'd be better off not creating your datagrid columns in code, but using bindings instead. Just bind the datagrid to the headings.Entities collection.

The same thing with your DataForm, just bind your item to it and it should create all the proper fields for you.

Bryant
yea, makes sense. I just need to work out how to bind the headings and data seperatly (i.e. I the headings are different to the binding field names)
Grayson Mitchell
Use the DisplayAttribute on the property and put the name in there.
Bryant
Thanks, I have posted a more specific follow up question here:http://stackoverflow.com/questions/1753187/dynamic-column-binding-in-xaml
Grayson Mitchell