开发者

Columns definition for DataGrid bound to DataTable with unknown columns?

开发者 https://www.devze.com 2023-01-16 04:49 出处:网络
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 Che

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号