Columns definition for DataGrid bound to DataTable with unknown columns?
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 cr开发者_运维问答eate 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....
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.
精彩评论