tags:

views:

12

answers:

1

I have a DataTable which is going to be bound to a DataGrid. I don't know what the columns will be in advance, however I do know the first column will be a boolean value that should be bound to a CheckBox.

Is there an easy way to create a DataGrid that will generate the unknown columns, but not show the first column? The unknown columns will need to maintain the sort functionality. AutoGenerateColumns would be nice if I could flag one of the columns as "DoNotShow" or something....

+1  A: 

You can handle the AutoGeneratingColumn event of the DataGrid and deny the column from appearing from there: http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.autogeneratingcolumn.aspx

If you don't want to handle it in code-behind, you can 'forward' the event to your view-model with help from a messaging/aggregation framework such as the Messaging system in MVVMLight.

Alex Paven
Thank you, I wasn't aware that there was an `AutoGeneratingColumns` event
Rachel