当AutoGenerateColumns = True时,有没有办法在DataGrid中隐藏特定的列? [英] Is there a way to hide a specific column in a DataGrid when AutoGenerateColumns=True?

查看:224
本文介绍了当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中隐藏特定的列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆