本文介绍了当AutoGenerateColumns = True时,有没有办法在DataGrid中隐藏特定的列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个WPF 4.0 DataGrid绑定到DataTable使用AutoGenerateColumns = True。列是动态的,但是我知道总是会有一个名为ID的列,我想隐藏这个列。有没有办法我可以这样做?解决方案
在您的datagrid中,订阅 AutoGeneratingColumn 事件,事件 args ( DataGridAutoGeneratingColumnEventArgs )的列名称为$ code>取消,如果列名称是ID,则设置 Cancel = true 。应该做的伎俩。
I have a WPF 4.0 DataGrid that is bound to a DataTable using AutoGenerateColumns=True. The columns are dynamic, however I know there is always going to be a column named ID and I would like to hide this column. Is there a way I can do this?
解决方案in your datagrid, subscribe for the AutoGeneratingColumn event, the event args (DataGridAutoGeneratingColumnEventArgs) has the column name and a "Cancel", if the column name is ID then set Cancel = true. should do the trick.
更多推荐
当AutoGenerateColumns = True时,有没有办法在DataGrid中隐藏特定的列?
发布评论